Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 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)