FIX: tăng velocity thêm tính năng midi key khác sử dụng cho midi note
This commit is contained in:
+12
-9
@@ -227,11 +227,12 @@ class ClientMIDIRecorder {
|
|||||||
// Command 0x9: Note On
|
// Command 0x9: Note On
|
||||||
if (command === 0x9 && velocity > 0) {
|
if (command === 0x9 && velocity > 0) {
|
||||||
const noteId = `rec_${Date.now()}_${pitch}`;
|
const noteId = `rec_${Date.now()}_${pitch}`;
|
||||||
|
const scaledVel = Math.min(1.0, Math.max(0.5, Math.round(velocity / 127.0 * 100) / 100));
|
||||||
const newActiveNote = {
|
const newActiveNote = {
|
||||||
id: noteId,
|
id: noteId,
|
||||||
pitch: pitch,
|
pitch: pitch,
|
||||||
start_beat: currentBeat,
|
start_beat: currentBeat,
|
||||||
velocity: velocity / 127.0
|
velocity: scaledVel
|
||||||
};
|
};
|
||||||
this.activeNotes.set(pitch, newActiveNote);
|
this.activeNotes.set(pitch, newActiveNote);
|
||||||
console.log(`[DevLog] [MIDI Rec] Note On - Pitch: ${pitch}, Velocity: ${velocity}, StartBeat: ${currentBeat.toFixed(3)}, latencyCompSec: ${this.latencyCompSec.toFixed(3)}, noteObj:`, newActiveNote);
|
console.log(`[DevLog] [MIDI Rec] Note On - Pitch: ${pitch}, Velocity: ${velocity}, StartBeat: ${currentBeat.toFixed(3)}, latencyCompSec: ${this.latencyCompSec.toFixed(3)}, noteObj:`, newActiveNote);
|
||||||
@@ -7807,10 +7808,12 @@ const App = () => {
|
|||||||
if (msg.data.length < 3) return;
|
if (msg.data.length < 3) return;
|
||||||
const cmd = msg.data[0] >> 4;
|
const cmd = msg.data[0] >> 4;
|
||||||
const pitch = msg.data[1];
|
const pitch = msg.data[1];
|
||||||
const velocity = msg.data[2];
|
const rawVel = msg.data[2];
|
||||||
if (cmd === 0x9 && velocity > 0) {
|
// Scale low MIDI velocity up to ensure audibility (min 64)
|
||||||
lastMidiNoteRef.current = { pitch, velocity, startTime: performance.now(), length: 0 };
|
const scaledVel = Math.min(127, Math.max(64, Math.round(rawVel * 1.5)));
|
||||||
setLastMidiNote({ pitch, velocity, length: 0, time: Date.now() });
|
if (cmd === 0x9 && rawVel > 0) {
|
||||||
|
lastMidiNoteRef.current = { pitch, velocity: scaledVel, startTime: performance.now(), length: 0 };
|
||||||
|
setLastMidiNote({ pitch, velocity: scaledVel, length: 0, time: Date.now() });
|
||||||
activeMidiPitchesRef.current.add(pitch);
|
activeMidiPitchesRef.current.add(pitch);
|
||||||
setActiveMidiPitches(new Set(activeMidiPitchesRef.current));
|
setActiveMidiPitches(new Set(activeMidiPitchesRef.current));
|
||||||
// Route MIDI input to ALL armed tracks on their dedicated channels
|
// Route MIDI input to ALL armed tracks on their dedicated channels
|
||||||
@@ -7826,7 +7829,7 @@ const App = () => {
|
|||||||
var asCh = window.SonicPianoRoll ? window.SonicPianoRoll.getTrackMidiChannel(asTrk, allTracks) : (asTrk ? asTrk.midiChannel : 0);
|
var asCh = window.SonicPianoRoll ? window.SonicPianoRoll.getTrackMidiChannel(asTrk, allTracks) : (asTrk ? asTrk.midiChannel : 0);
|
||||||
var asProg = as.instrumentProgram;
|
var asProg = as.instrumentProgram;
|
||||||
var asSe = as.synth_engine;
|
var asSe = as.synth_engine;
|
||||||
window.SonicSF.playNote(pitch, velocity, 60000, undefined, asProg, null, asCh, asSe);
|
window.SonicSF.playNote(pitch, scaledVel, 60000, undefined, asProg, null, asCh, asSe);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Route to ALL armed tracks (not just the first one)
|
// Route to ALL armed tracks (not just the first one)
|
||||||
@@ -7835,10 +7838,10 @@ const App = () => {
|
|||||||
var atProg = at.instrumentProgram;
|
var atProg = at.instrumentProgram;
|
||||||
var atSe = at.synth_engine;
|
var atSe = at.synth_engine;
|
||||||
var atDest = activeTrackNodesRef.current[at.id]?.gainNode || null;
|
var atDest = activeTrackNodesRef.current[at.id]?.gainNode || null;
|
||||||
window.SonicSF.playNote(pitch, velocity, 60000, undefined, atProg, atDest, atCh, atSe);
|
window.SonicSF.playNote(pitch, scaledVel, 60000, undefined, atProg, atDest, atCh, atSe);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (cmd === 0x8 || (cmd === 0x9 && velocity === 0)) {
|
} else if (cmd === 0x8 || (cmd === 0x9 && rawVel === 0)) {
|
||||||
activeMidiPitchesRef.current.delete(pitch);
|
activeMidiPitchesRef.current.delete(pitch);
|
||||||
setActiveMidiPitches(new Set(activeMidiPitchesRef.current));
|
setActiveMidiPitches(new Set(activeMidiPitchesRef.current));
|
||||||
const current = lastMidiNoteRef.current;
|
const current = lastMidiNoteRef.current;
|
||||||
@@ -12246,9 +12249,9 @@ const App = () => {
|
|||||||
|
|
||||||
for (let trackId in midiRecorders) {
|
for (let trackId in midiRecorders) {
|
||||||
const midiRec = midiRecorders[trackId];
|
const midiRec = midiRecorders[trackId];
|
||||||
|
const recordedNotes = midiRec.stop();
|
||||||
|
|
||||||
if (midiRec.tempTabId) {
|
if (midiRec.tempTabId) {
|
||||||
const recordedNotes = midiRec.stop();
|
|
||||||
if (recordedNotes.length > 0) {
|
if (recordedNotes.length > 0) {
|
||||||
const newNotes = recordedNotes.map((n, i) => ({
|
const newNotes = recordedNotes.map((n, i) => ({
|
||||||
id: 'rec_' + Date.now() + '_' + i,
|
id: 'rec_' + Date.now() + '_' + i,
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user