fix: midi message parsing in front and remove delay in scorometer

This commit is contained in:
GitBluub
2023-05-22 14:42:18 +09:00
committed by Clément Le Bihan
parent 004ffa0be8
commit c5a7436e2c
2 changed files with 24 additions and 9 deletions

View File

@@ -35,6 +35,15 @@ if (process.env.NODE_ENV != 'development' && Platform.OS === 'web') {
}
}
function parseMidiMessage(message) {
return {
command: message.data[0] >> 4,
channel: message.data[0] & 0xf,
note: message.data[1],
velocity: message.data[2] / 127,
};
}
const PlayView = ({ songId, type, route }: RouteProps<PlayViewProps>) => {
const accessToken = useSelector((state: RootState) => state.user.accessToken);
const navigation = useNavigation();
@@ -153,16 +162,21 @@ const PlayView = ({ songId, type, route }: RouteProps<PlayViewProps>) => {
return;
}
input.onmidimessage = (message) => {
const keyIsPressed = message.data[2] == 100;
const { command, channel, note, velocity } = parseMidiMessage(message);
console.log(command, channel, note, velocity);
const keyIsPressed = command == 9;
console.log(keyIsPressed);
const keyCode = message.data[1];
// console.log('Playing midi ' + keyCode + ' at time ' + getElapsedTime());
webSocket.current?.send(JSON.stringify({
type: keyIsPressed ? "note_on" : "note_off",
note: keyCode,
id: song.data!.id,
time: getElapsedTime()
}))
}
webSocket.current?.send(
JSON.stringify({
type: keyIsPressed ? "note_on" : "note_off",
note: keyCode,
id: song.data!.id,
time: getElapsedTime(),
})
);
};
inputIndex++;
});
}

View File

@@ -76,7 +76,8 @@ class Scorometer:
def getPartition(self, midiFile: str):
notes = []
s = 3500
s = 3000
s = 0
notes_on = {}
prev_note_on = {}
for msg in MidiFile(midiFile):