Skip to content

Commit

Permalink
[project-s] インポート周りの修正とリファクタリング (VOICEVOX#1614)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigprogramming authored Oct 19, 2023
1 parent d7a28d3 commit 645ab4b
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 249 deletions.
21 changes: 10 additions & 11 deletions src/components/Sing/ScoreSequencer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default defineComponent({
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 @@ export default defineComponent({
note: {
id,
position,
midi: noteNumber,
noteNumber,
duration,
lyric,
},
Expand Down Expand Up @@ -337,10 +337,10 @@ export default defineComponent({
}
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 @@ export default defineComponent({
}
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 @@ export default defineComponent({
}
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 @@ export default defineComponent({
});
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 @@ -84,15 +84,15 @@ export default defineComponent({
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

0 comments on commit 645ab4b

Please sign in to comment.