From e12e435a18a3a04dba389cabfcb5d54ce2d28527 Mon Sep 17 00:00:00 2001 From: rhetr Date: Sun, 8 Feb 2015 12:12:10 -0800 Subject: [PATCH 1/3] update midiseq-ui to use 48 ppq --- source/native-plugins/resources/midiseq-ui | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source/native-plugins/resources/midiseq-ui b/source/native-plugins/resources/midiseq-ui index a8ce67fcc..d29c6561c 100755 --- a/source/native-plugins/resources/midiseq-ui +++ b/source/native-plugins/resources/midiseq-ui @@ -904,6 +904,8 @@ class MainWindow(ExternalUI, QWidget): "sigDenom": 4.0 } + self.PPQ = 48. + self.initUI() self.piano.midievent.connect(self.sendMsg) self.piano.measureupdate.connect(self.updateMeasureBox) @@ -1057,15 +1059,15 @@ class MainWindow(ExternalUI, QWidget): msg = data[0] if msg == "midievent-remove": note, start, length, vel = data[1:5] - note_start = start * 60. / self.fTransportInfo["bpm"] * 4. / self.fTransportInfo["sigDenom"] * self.getSampleRate() - note_stop = note_start + length * 60. / self.fTransportInfo["bpm"] * 4. * self.fTransportInfo["sigNum"] / self.fTransportInfo["sigDenom"] * self.getSampleRate() + note_start = start * 60. / self.fTransportInfo["bpm"] * 4. / self.fTransportInfo["sigDenom"] * self.PPQ + note_stop = note_start + length * 60. / self.fTransportInfo["bpm"] * 4. * self.fTransportInfo["sigNum"] / self.fTransportInfo["sigDenom"] * self.PPQ self.send([msg, note_start, 3, MIDI_STATUS_NOTE_ON, note, vel]) self.send([msg, note_stop, 3, MIDI_STATUS_NOTE_OFF, note, vel]) elif msg == "midievent-add": note, start, length, vel = data[1:5] - note_start = start * 60. / self.fTransportInfo["bpm"] * self.getSampleRate() - note_stop = note_start + length * 60. / self.fTransportInfo["bpm"] * 4. * self.fTransportInfo["sigNum"] / self.fTransportInfo["sigDenom"] * self.getSampleRate() + note_start = start * 60. / self.fTransportInfo["bpm"] * self.PPQ + note_stop = note_start + length * 60. / self.fTransportInfo["bpm"] * 4. * self.fTransportInfo["sigNum"] / self.fTransportInfo["sigDenom"] * self.PPQ self.send([msg, note_start, 3, MIDI_STATUS_NOTE_ON, note, vel]) self.send([msg, note_stop, 3, MIDI_STATUS_NOTE_OFF, note, vel]) @@ -1113,7 +1115,7 @@ class MainWindow(ExternalUI, QWidget): "sigDenom": sigDenom } - #self.piano.movePlayHead(self.fTransportInfo) + self.piano.movePlayHead(self.fTransportInfo) elif msg == "show": @@ -1146,7 +1148,7 @@ class MainWindow(ExternalUI, QWidget): # we'll convert it to a smaller value for now (seconds) # later on we can have time as PPQ or similar - time /= self.getSampleRate() + time /= self.PPQ status = MIDI_GET_STATUS_FROM_DATA(data) channel = MIDI_GET_CHANNEL_FROM_DATA(data) From 635a0f261abb5ab19874d6db90f9e3bee56330cf Mon Sep 17 00:00:00 2001 From: rhetr Date: Sun, 8 Feb 2015 13:12:16 -0800 Subject: [PATCH 2/3] adding midievents to refreshScene --- source/native-plugins/resources/midiseq-ui | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/native-plugins/resources/midiseq-ui b/source/native-plugins/resources/midiseq-ui index d29c6561c..fcd6753f7 100755 --- a/source/native-plugins/resources/midiseq-ui +++ b/source/native-plugins/resources/midiseq-ui @@ -703,10 +703,14 @@ class PianoRoll(QGraphicsScene): for note in self.notes[:]: if note.note[1] >= (self.num_measures * self.time_sig[0]): self.notes.remove(note) + self.midievent.emit(["midievent-remove", note.note[0], note.note[1], note.note[2], note.note[3]]) elif note.note[2] > self.max_note_length: - new_note = note.note + new_note = note.note[:] + new_note[2] = self.max_note_length self.notes.remove(note) self.drawNote(new_note[0], new_note[1], self.max_note_length, new_note[3], False) + self.midievent.emit(["midievent-remove", note.note[0], note.note[1], note.note[2], note.note[3]]) + self.midievent.emit(["midievent-add", new_note[0], new_note[1], new_note[2], new_note[3]]) list(map(self.addItem, self.notes)) if self.views(): self.views()[0].setSceneRect(self.itemsBoundingRect()) From 0fd0021fa6a93ec3bda7668c51f038fe31eb2b86 Mon Sep 17 00:00:00 2001 From: rhetr Date: Sun, 8 Feb 2015 13:11:11 -0800 Subject: [PATCH 3/3] moving midiseq playhead only works for 120bpm right now --- source/native-plugins/resources/midiseq-ui | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/native-plugins/resources/midiseq-ui b/source/native-plugins/resources/midiseq-ui index fcd6753f7..ad25ddb41 100755 --- a/source/native-plugins/resources/midiseq-ui +++ b/source/native-plugins/resources/midiseq-ui @@ -373,9 +373,11 @@ class PianoRoll(QGraphicsScene): # ------------------------------------------------------------------------- # Callbacks - def movePlayHead(self, t): - total_duration = 1920 * self.time_sig[0] * self.num_measures - pos = t['bar']*1920*self.time_sig[0] + t['beat']*1920 + t['tick'] + def movePlayHead(self, transport_info): + # TODO: need conversion between frames and PPQ + x = 105. # works for 120bpm + total_duration = self.time_sig[0] * self.num_measures * x + pos = transport_info['frame'] / x frac = (pos % total_duration) / total_duration self.play_head.setPos(QPointF(frac * self.grid_width, 0)) @@ -1108,6 +1110,8 @@ class MainWindow(ExternalUI, QWidget): if beat != self.fTransportInfo["beat"]: print(beat) + old_frame = self.fTransportInfo['frame'] + self.fTransportInfo = { "playing": playing, "frame": frame, @@ -1119,7 +1123,8 @@ class MainWindow(ExternalUI, QWidget): "sigDenom": sigDenom } - self.piano.movePlayHead(self.fTransportInfo) + if old_frame != frame: + self.piano.movePlayHead(self.fTransportInfo) elif msg == "show":