fix: midi message parsing in front and remove delay in scorometer
This commit is contained in:
committed by
Clément Le Bihan
parent
004ffa0be8
commit
c5a7436e2c
@@ -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++;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user