def test_eq(self): self.assertTrue( MidiMessage.noteOn(1, 0, 100) == MidiMessage.noteOn(1, 0, 100)) self.assertFalse( MidiMessage.noteOn(1, 1, 100) == MidiMessage.noteOn(1, 0, 100)) self.assertFalse( MidiMessage.pitchWheel(1, 1) == MidiMessage.noteOn(1, 64, 1)) self.assertTrue( MidiMessage.controllerEvent(1, 100, 1) == MidiMessage.controllerEvent(1, 100, 1)) self.assertTrue( MidiMessage.controllerEvent(1, 100, 2) == MidiMessage.controllerEvent(1, 100, 2)) self.assertTrue( MidiMessage.controllerEvent(1, 100, 3) == MidiMessage.controllerEvent(1, 100, 3)) self.assertFalse( MidiMessage.controllerEvent(1, 101, 1) == MidiMessage.controllerEvent(1, 100, 1)) self.assertFalse( MidiMessage.controllerEvent(1, 102, 2) == MidiMessage.controllerEvent(1, 100, 2)) self.assertFalse( MidiMessage.controllerEvent(1, 103, 3) == MidiMessage.controllerEvent(1, 100, 3))
def test_operators(self): m1 = MidiMessage.noteOn(1, 100, 120) m2 = MidiMessage.noteOn(1, 100, 120) self.assertEqual(m1, m2) m3 = MidiMessage.noteOn(1, 101, 120) self.assertNotEqual(m1, m3)
def test_operators(self): m1 = MidiMessage.noteOn(1, 100, 120) m2 = MidiMessage.noteOn(1, 100, 120) self.assertEqual(m1, m2) m3 = MidiMessage.noteOn(1, 101, 120) self.assertNotEqual(m1, m3)
def from_dist_vec(vector): """Create gesture by drawing a random instance from the distribution vector representation""" starting_pitch, num_notes, vel_mean, vel_std, int_mean, int_std, \ diff_mean, diff_std, len_mean, len_std = vector g = Gesture() prev_nn = 0 # midi note number for previous note on prev_time = 0 # start time for previous note on # randomize number of notes using a poisson distribution num_notes = max(np.random.poisson(num_notes), 1) # random generate a similar gesture based on attribute normal distributions for i in range(num_notes): # if no messages have been written, use starting pitch if g.messages == []: g.messages.append( MidiMessage.noteOn(1, starting_pitch, int(round(normal(vel_mean, vel_std)))) ) g.msg_times.append(0.0) g.messages.append( MidiMessage.noteOff(1, starting_pitch) ) g.msg_times.append(normal(len_mean, len_std)) prev_nn = starting_pitch prev_time = 0.0 else: nn = prev_nn + int(round(normal(int_mean, int_std))) # if note is out of the keyboard's range, wrap it by octave into range if nn > 108: nn -= -((108-nn) // 12) * 12 if nn < 21: nn += -((nn-21) // 12) * 12 time = prev_time + normal(diff_mean, diff_std) g.messages.append( MidiMessage.noteOn(1, nn, int(round(normal(vel_mean, vel_std)))) ) g.msg_times.append(time) g.messages.append( MidiMessage.noteOff(1, nn) ) g.msg_times.append(time + normal(len_mean, len_std)) prev_nn = nn prev_time = time g.collect() return g
def from_data_matrix(mat, scaled=True): """Create gesture using data matrix respresentation""" g = Gesture() # gesture start time t_start = min(mat[:, 2]) for (n, v, t, l) in mat: # shift messages to start at time zero if they dont already t -= t_start if scaled: n = np.interp(n, [0, 1], [21, 108]) v = np.interp(v, [0, 1], [0, 127]) t = np.interp(t, [0, 1], [0, 20]) l = np.interp(l, [0, 1], [0.05, 10]) g.messages.append( MidiMessage.noteOn(1, int(n), int(v)) ) g.msg_times.append(t) g.messages.append( MidiMessage.noteOff(1, int(n)) ) g.msg_times.append(t + l) g.collect() return g
def test_eq(self): self.assertTrue(MidiMessage.noteOn(1, 0, 100) == MidiMessage.noteOn(1, 0, 100)) self.assertFalse(MidiMessage.noteOn(1, 1, 100) == MidiMessage.noteOn(1, 0, 100)) self.assertFalse(MidiMessage.pitchWheel(1, 1) == MidiMessage.noteOn(1, 64, 1)) self.assertTrue(MidiMessage.controllerEvent(1, 100, 1) == MidiMessage.controllerEvent(1, 100, 1)) self.assertTrue(MidiMessage.controllerEvent(1, 100, 2) == MidiMessage.controllerEvent(1, 100, 2)) self.assertTrue(MidiMessage.controllerEvent(1, 100, 3) == MidiMessage.controllerEvent(1, 100, 3)) self.assertFalse(MidiMessage.controllerEvent(1, 101, 1) == MidiMessage.controllerEvent(1, 100, 1)) self.assertFalse(MidiMessage.controllerEvent(1, 102, 2) == MidiMessage.controllerEvent(1, 100, 2)) self.assertFalse(MidiMessage.controllerEvent(1, 103, 3) == MidiMessage.controllerEvent(1, 100, 3))
def test_raw(self): m1 = MidiMessage.noteOn(5, 123, 45) data = m1.getRawData() size = m1.getRawDataSize() self.assertEqual(size, len(data)) m2 = MidiMessage(data) self.assertEqual(m1, m2) # m1 = MidiMessage.controllerEvent(12, 123, 45) data = m1.getRawData() size = m1.getRawDataSize() self.assertEqual(size, len(data)) m2 = MidiMessage(data) self.assertEqual(m1, m2)
def test_raw(self): m1 = MidiMessage.noteOn(5, 123, 45) data = m1.getRawData() size = m1.getRawDataSize() self.assertEqual(size, len(data)) m2 = MidiMessage(data) self.assertEqual(m1, m2) # m1 = MidiMessage.controllerEvent(12, 123, 45) data = m1.getRawData() size = m1.getRawDataSize() self.assertEqual(size, len(data)) m2 = MidiMessage(data) self.assertEqual(m1, m2)
def updateValue(self): if not self.midimessage: return channel = self.channelBox.currentIndex() + 1 if self.typeBox.currentText() == util.ANY_TEXT: midi = MidiMessage.allNotesOff(0) elif self.typeBox.currentIndex() == 0: midi = MidiMessage.noteOn(channel, self.noteNumBox.currentIndex(), self.noteVelBox.currentIndex()+1) elif self.typeBox.currentIndex() == 1: midi = MidiMessage.noteOff(channel, self.noteNumBox.currentIndex()) elif self.typeBox.currentIndex() == 2: midi = MidiMessage.controllerEvent(channel, self.ccNumBox.currentIndex(), self.ccValueBox.currentIndex()) elif self.typeBox.currentIndex() == 3: midi = MidiMessage.aftertouchChange(channel, self.atNumBox.currentIndex(), self.atValueBox.currentIndex()) if self.portBox.currentIndex() == -1: portName = None else: portName = self.portBox.currentText() if not self.isInitting: self.midimessage.setWildcard('channel', self.channelBox.currentText() in [util.ANY_TEXT, util.ALL_TEXT], emit=False) self.midimessage.setWildcard('type', self.typeBox.currentText() in [util.ANY_TEXT, util.ALL_TEXT], emit=False) self.midimessage.setWildcard('noteNum', self.noteNumBox.currentText() in [util.ANY_TEXT, util.ALL_TEXT], emit=False) self.midimessage.setWildcard('noteVel', self.noteVelBox.currentText() in [util.ANY_TEXT, util.ALL_TEXT], emit=False) self.midimessage.setWildcard('ccNum', self.ccNumBox.currentText() in [util.ANY_TEXT, util.ALL_TEXT], emit=False) self.midimessage.setWildcard('ccValue', self.ccValueBox.currentText() in [util.ANY_TEXT, util.ALL_TEXT], emit=False) self.midimessage.setWildcard('atNum', self.atNumBox.currentText() in [util.ANY_TEXT, util.ALL_TEXT], emit=False) self.midimessage.setWildcard('atValue', self.atValueBox.currentText() in [util.ANY_TEXT, util.ALL_TEXT], emit=False) self.midimessage.setMidi(portName, midi)
def do_SenderProc(iq, oq, portName): DEBUG = 0 def wait_for(x): s = iq.get(block=True, timeout=2) if s != x: print("%s: OH SHIT (wait_for() %s != %s)" % (__name__, s, x)) device = RtMidiOut() if DEBUG: print('%s: OPENING %s' % (__name__, portName)) device.openVirtualPort(portName) oq.put('init') # the port is open wait_for('start') total = 0 # note on for i in range(128): for j in range(1, 128): if DEBUG: print("%s: Note %i %i" % (__name__, i, j)) m = MidiMessage.noteOn(1, i, j) device.sendMessage(m) wait_for('next') total += 1 # controller for i in range(128): for j in range(128): if DEBUG: print("%s: CC %i %i" % (__name__, i, j)) m = MidiMessage.controllerEvent(1, i, j) device.sendMessage(m) wait_for('next') total += 1 wait_for('done') print('%s: sent %i messages' % (__name__, total))
def do_SenderProc(iq, oq, portName): DEBUG = 0 def wait_for(x): s = iq.get(block=True, timeout=2) if s != x: print("%s: OH SHIT (wait_for() %s != %s)" % (__name__, s, x)) device = RtMidiOut() if DEBUG: print('%s: OPENING %s' % (__name__, portName)) device.openVirtualPort(portName) oq.put('init') # the port is open wait_for('start') total = 0 # note on for i in range(128): for j in range(1, 128): if DEBUG: print("%s: Note %i %i" % (__name__, i, j)) m = MidiMessage.noteOn(1, i, j) device.sendMessage(m) wait_for('next') total += 1 # controller for i in range(128): for j in range(128): if DEBUG: print("%s: CC %i %i" % (__name__, i, j)) m = MidiMessage.controllerEvent(1, i, j) device.sendMessage(m) wait_for('next') total += 1 wait_for('done') print('%s: sent %i messages' % (__name__, total))
def test_noteOnChannel(self): """ https://github.com/patrickkidd/pyrtmidi/issues/13 """ m = MidiMessage.noteOn(10, 12, 13) self.assertEqual(m.getChannel(), 10) self.assertEqual(m.getNoteNumber(), 12) self.assertEqual(m.getVelocity(), 13)
def test_copy(self): m1 = MidiMessage.noteOn(5, 123, 45) m2 = MidiMessage(m1) self.assertEqual(m1, m2) self.assertEqual(m1.getChannel(), m2.getChannel())
def sendNoteSignal(self, note, vel, wait=.1): m = MidiMessage.noteOn(self.channel, note, vel) self.output(m) time.sleep(wait) m = MidiMessage.noteOff(self.channel, note) self.output(m)
def test_copy(self): m1 = MidiMessage.noteOn(5, 123, 45) m2 = MidiMessage(m1) self.assertEqual(m1, m2) self.assertEqual(m1.getChannel(), m2.getChannel())
def test_noteOnChannel(self): """ https://github.com/patrickkidd/pyrtmidi/issues/13 """ m = MidiMessage.noteOn(10, 12, 13) self.assertEqual(m.getChannel(), 10) self.assertEqual(m.getNoteNumber(), 12) self.assertEqual(m.getVelocity(), 13)