Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[project-s] インポート周りの修正とリファクタリング #1614

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/components/Sing/ScoreSequencer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
:index="index"
:cursor-x="cursorX"
:cursor-y="cursorY"
@handleNotesKeydown="handleNotesKeydown"

Check warning on line 88 in src/components/Sing/ScoreSequencer.vue

View workflow job for this annotation

GitHub Actions / build-test

v-on event '@handleNotesKeydown' must be hyphenated

Check warning on line 88 in src/components/Sing/ScoreSequencer.vue

View workflow job for this annotation

GitHub Actions / lint

v-on event '@handleNotesKeydown' must be hyphenated
@handleDragMoveStart="handleDragMoveStart"

Check warning on line 89 in src/components/Sing/ScoreSequencer.vue

View workflow job for this annotation

GitHub Actions / build-test

v-on event '@handleDragMoveStart' must be hyphenated

Check warning on line 89 in src/components/Sing/ScoreSequencer.vue

View workflow job for this annotation

GitHub Actions / lint

v-on event '@handleDragMoveStart' must be hyphenated
@handleDragRightStart="handleDragRightStart"

Check warning on line 90 in src/components/Sing/ScoreSequencer.vue

View workflow job for this annotation

GitHub Actions / build-test

v-on event '@handleDragRightStart' must be hyphenated

Check warning on line 90 in src/components/Sing/ScoreSequencer.vue

View workflow job for this annotation

GitHub Actions / lint

v-on event '@handleDragRightStart' must be hyphenated
@handleDragLeftStart="handleDragLeftStart"

Check warning on line 91 in src/components/Sing/ScoreSequencer.vue

View workflow job for this annotation

GitHub Actions / build-test

v-on event '@handleDragLeftStart' must be hyphenated

Check warning on line 91 in src/components/Sing/ScoreSequencer.vue

View workflow job for this annotation

GitHub Actions / lint

v-on event '@handleDragLeftStart' must be hyphenated
/>
</div>
<!-- NOTE: スクロールバー+ズームレンジ仮 -->
Expand Down Expand Up @@ -172,7 +172,7 @@
const dragMoveCurrentY = ref();
const dragDurationCurrentX = ref();
// 分解能(Ticks Per Quarter Note)
const tpqn = computed(() => state.score?.resolution ?? 480);
const tpqn = computed(() => state.score?.tpqn ?? 480);
// ノート
const notes = computed(() => state.score?.notes ?? []);
// 拍子
Expand Down Expand Up @@ -263,7 +263,7 @@
note: {
id,
position,
midi: noteNumber,
noteNumber,
duration,
lyric,
},
Expand Down Expand Up @@ -337,10 +337,10 @@
}
isNotesChanged = true;
const position = note.position + amountPositionX;
const noteNumber = note.midi + amountPositionY;
const noteNumber = note.noteNumber + amountPositionY;
return {
...note,
midi: noteNumber,
noteNumber,
position,
};
} else {
Expand Down Expand Up @@ -506,16 +506,16 @@
}
const newNotes = state.score.notes.map((note) => {
if (selectedNoteIds.value.includes(note.id)) {
const noteNumber = Math.min(note.midi + 1, 127);
const noteNumber = Math.min(note.noteNumber + 1, 127);
return {
...note,
midi: noteNumber,
noteNumber,
};
} else {
return note;
}
});
if (newNotes.some((note) => note.midi > 127)) {
if (newNotes.some((note) => note.noteNumber > 127)) {
return;
}
store.dispatch("REPLACE_ALL_NOTES", { notes: newNotes });
Expand All @@ -527,16 +527,16 @@
}
const newNotes = state.score.notes.map((note) => {
if (selectedNoteIds.value.includes(note.id)) {
const noteNumber = Math.max(note.midi - 1, 0);
const noteNumber = Math.max(note.noteNumber - 1, 0);
return {
...note,
midi: noteNumber,
noteNumber,
};
} else {
return note;
}
});
if (newNotes.some((note) => note.midi < 0)) {
if (newNotes.some((note) => note.noteNumber < 0)) {
return;
}
store.dispatch("REPLACE_ALL_NOTES", { notes: newNotes });
Expand Down Expand Up @@ -622,7 +622,6 @@
});

return {
measureNum,
beatsPerMeasure,
beatWidth,
gridCellWidth,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Sing/SequencerNote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
props: {
note: { type: Object as PropType<Note>, required: true },
index: { type: Number, required: true },
cursorX: { type: Number },

Check warning on line 73 in src/components/Sing/SequencerNote.vue

View workflow job for this annotation

GitHub Actions / build-test

Prop 'cursorX' requires default value to be set

Check warning on line 73 in src/components/Sing/SequencerNote.vue

View workflow job for this annotation

GitHub Actions / lint

Prop 'cursorX' requires default value to be set
cursorY: { type: Number },

Check warning on line 74 in src/components/Sing/SequencerNote.vue

View workflow job for this annotation

GitHub Actions / build-test

Prop 'cursorY' requires default value to be set

Check warning on line 74 in src/components/Sing/SequencerNote.vue

View workflow job for this annotation

GitHub Actions / lint

Prop 'cursorY' requires default value to be set
},

emits: [
Expand All @@ -84,15 +84,15 @@
setup(props, { emit }) {
const store = useStore();
const state = store.state;
const tpqn = computed(() => state.score?.resolution ?? 480);
const tpqn = computed(() => state.score?.tpqn ?? 480);
const zoomX = computed(() => state.sequencerZoomX);
const zoomY = computed(() => state.sequencerZoomY);
const positionX = computed(() => {
const noteStartTicks = props.note.position;
return tickToBaseX(noteStartTicks, tpqn.value) * zoomX.value;
});
const positionY = computed(() => {
const noteNumber = props.note.midi;
const noteNumber = props.note.noteNumber;
return noteNumberToBaseY(noteNumber + 0.5) * zoomY.value;
});
const barHeight = computed(() => getKeyBaseHeight() * zoomY.value);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sing/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export default defineComponent({
});
const snapTypeSelectOptions = computed(() => {
const tpqn = store.state.score?.resolution ?? 480;
const tpqn = store.state.score?.tpqn ?? 480;
return getSnapTypes(tpqn).map((snapType) => {
if (isTriplet(snapType)) {
return { snapType, label: `1/${(snapType / 3) * 2}(三連符)` };
Expand Down
42 changes: 21 additions & 21 deletions src/infrastructures/AudioRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,17 @@ export interface Instrument {
* ノートオンをスケジュールします。
* すでに指定されたノート番号でノートオンがスケジュールされている場合は何も行いません。
* @param contextTime ノートオンを行う時刻(コンテキスト時間)
* @param midi MIDIノート番号
* @param noteNumber MIDIノート番号
*/
noteOn(contextTime: number, midi: number): void;
noteOn(contextTime: number, noteNumber: number): void;

/**
* ノートオフをスケジュールします。
* すでに指定されたノート番号でノートオフがスケジュールされている場合は何も行いません。
* @param contextTime ノートオフを行う時刻(コンテキスト時間)
* @param midi MIDIノート番号
* @param noteNumber MIDIノート番号
*/
noteOff(contextTime: number, midi: number): void;
noteOff(contextTime: number, noteNumber: number): void;

/**
* 発音中のすべての音に対して、ノートオフのスケジュールを行います。
Expand All @@ -436,7 +436,7 @@ export interface Instrument {
export type NoteEvent = {
readonly noteOnTime: number;
readonly noteOffTime: number;
readonly midi: number;
readonly noteNumber: number;
};

/**
Expand Down Expand Up @@ -502,8 +502,8 @@ class NoteEventScheduler implements EventScheduler {
this.startContextTime + (event.noteOffTime - this.startTime);

if (event.noteOnTime < untilTime) {
this.instrument.noteOn(noteOnContextTime, event.midi);
this.instrument.noteOff(noteOffContextTime, event.midi);
this.instrument.noteOn(noteOnContextTime, event.noteNumber);
this.instrument.noteOff(noteOffContextTime, event.noteNumber);
this.index++;
} else break;
}
Expand Down Expand Up @@ -647,7 +647,7 @@ export type Envelope = {
};

type SynthVoiceParams = {
readonly midi: number;
readonly noteNumber: number;
readonly oscillatorType: OscillatorType;
readonly envelope: Envelope;
};
Expand All @@ -656,7 +656,7 @@ type SynthVoiceParams = {
* シンセサイザーのボイスです。音を合成します。
*/
class SynthVoice {
readonly midi: number;
readonly noteNumber: number;
private readonly oscillatorNode: OscillatorNode;
private readonly gainNode: GainNode;
private readonly envelope: Envelope;
Expand All @@ -678,7 +678,7 @@ class SynthVoice {
}

constructor(audioContext: BaseAudioContext, params: SynthVoiceParams) {
this.midi = params.midi;
this.noteNumber = params.noteNumber;
this.envelope = params.envelope;

this.oscillatorNode = new OscillatorNode(audioContext);
Expand All @@ -692,11 +692,11 @@ class SynthVoice {

/**
* MIDIノート番号を周波数に変換します。
* @param midi MIDIノート番号
* @param noteNumber MIDIノート番号
* @returns 周波数(Hz)
*/
private midiToFrequency(midi: number) {
return 440 * 2 ** ((midi - 69) / 12);
private midiToFrequency(noteNumber: number) {
return 440 * 2 ** ((noteNumber - 69) / 12);
}

/**
Expand All @@ -715,7 +715,7 @@ class SynthVoice {
this.gainNode.gain.linearRampToValueAtTime(1, t0 + atk);
this.gainNode.gain.setTargetAtTime(sus, t0 + atk, dcy);

const freq = this.midiToFrequency(this.midi);
const freq = this.midiToFrequency(this.noteNumber);
this.oscillatorNode.frequency.value = freq;

this.oscillatorNode.start(contextTime);
Expand Down Expand Up @@ -797,16 +797,16 @@ export class PolySynth implements Instrument {
* ノートオンをスケジュールします。
* すでに指定されたノート番号でノートオンがスケジュールされている場合は何も行いません。
* @param contextTime ノートオンを行う時刻(コンテキスト時間)
* @param midi MIDIノート番号
* @param noteNumber MIDIノート番号
*/
noteOn(contextTime: number, midi: number) {
noteOn(contextTime: number, noteNumber: number) {
const exists = this.voices.some((value) => {
return value.isActive && value.midi === midi;
return value.isActive && value.noteNumber === noteNumber;
});
if (exists) return;

const voice = new SynthVoice(this.audioContext, {
midi,
noteNumber,
oscillatorType: this.oscillatorType,
envelope: this.envelope,
});
Expand All @@ -822,11 +822,11 @@ export class PolySynth implements Instrument {
* ノートオフをスケジュールします。
* すでに指定されたノート番号でノートオフがスケジュールされている場合は何も行いません。
* @param contextTime ノートオフを行う時刻(コンテキスト時間)
* @param midi MIDIノート番号
* @param noteNumber MIDIノート番号
*/
noteOff(contextTime: number, midi: number) {
noteOff(contextTime: number, noteNumber: number) {
const voice = this.voices.find((value) => {
return value.isActive && value.midi === midi;
return value.isActive && value.noteNumber === noteNumber;
});
if (!voice) return;

Expand Down
Loading