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:
2026-07-29 22:34:05 +07:00
parent 971dad84e7
commit 66eef405a7
2 changed files with 18 additions and 14 deletions
+12 -9
View File
@@ -227,11 +227,12 @@ class ClientMIDIRecorder {
// Command 0x9: Note On
if (command === 0x9 && velocity > 0) {
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 = {
id: noteId,
pitch: pitch,
start_beat: currentBeat,
velocity: velocity / 127.0
velocity: scaledVel
};
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);
@@ -7807,10 +7808,12 @@ const App = () => {
if (msg.data.length < 3) return;
const cmd = msg.data[0] >> 4;
const pitch = msg.data[1];
const velocity = msg.data[2];
if (cmd === 0x9 && velocity > 0) {
lastMidiNoteRef.current = { pitch, velocity, startTime: performance.now(), length: 0 };
setLastMidiNote({ pitch, velocity, length: 0, time: Date.now() });
const rawVel = msg.data[2];
// Scale low MIDI velocity up to ensure audibility (min 64)
const scaledVel = Math.min(127, Math.max(64, Math.round(rawVel * 1.5)));
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);
setActiveMidiPitches(new Set(activeMidiPitchesRef.current));
// 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 asProg = as.instrumentProgram;
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)
@@ -7835,10 +7838,10 @@ const App = () => {
var atProg = at.instrumentProgram;
var atSe = at.synth_engine;
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);
setActiveMidiPitches(new Set(activeMidiPitchesRef.current));
const current = lastMidiNoteRef.current;
@@ -12246,9 +12249,9 @@ const App = () => {
for (let trackId in midiRecorders) {
const midiRec = midiRecorders[trackId];
const recordedNotes = midiRec.stop();
if (midiRec.tempTabId) {
const recordedNotes = midiRec.stop();
if (recordedNotes.length > 0) {
const newNotes = recordedNotes.map((n, i) => ({
id: 'rec_' + Date.now() + '_' + i,
File diff suppressed because one or more lines are too long