import scheduler
import random

from midiutils import a_note, a_scale

if __name__ == "__main__":
  m = midiobj.MidiObj([u"yoshimi:midi in", u"LinuxSampler:midi_in_0"])
  s = scheduler.Scheduler(0.01)


  raw_input ("Please make synthesizer connections. Press enter to continue...")
  
  # define schedule
  # fragment 1: pads
  s.add_fragment(padgen.PadGen("Pad1", 
                               [a_note("C4")], # a_note("D4"), a_note("E4"), a_note("G4"), a_note("A4") ], # notes
                               [1, 0.333],                       # durations
                               [ (i+1)*10 for i in range(11) ],  # velocities
                               [0, 1, 2],                        # octaves
                               [1, 2, 4, 8],                     # strettos
                               m,                                # midiobject
                               1),                               # midi channel 1
                               0, 30)                            # time 0 to 30

  # fragment 2: bells
  s.add_fragment(padgen.PadGen("Bells2",
                               [a_note("C4"), a_note("Db4"), a_note("Eb4"), a_note("E4")], # notes
                               [0.333],                          # durations
                               [ (i+1)*10 for i in range(11) ],  # velocities
                               [-2, -1, 0, 1],                   # octaves
                               [1, 0.5, 0.25, 0.125],            # strettos
        if not q.empty():
          off = q.get()
          print "NOTEINTERPOLATOR {0}: NOTE OFF note: {1} channel: {2}".format(self.instrname, a_name(off[1]), self.channel)
          m.send_message(off)

    self.cleanup()

  def cleanup(self):
    """
    send note off msgs to all notes that were still running
    """
    while not self.q.empty():
      off = self.q.get()
      print "NOTEINTERPOLATOR {0}: NOTE OFF note: {1} channel: {2}".format(self.instrname, a_name(off[1]), self.channel)
      self.midi.send_message(off)

if __name__ == "__main__":
  from midiutils import a_note
  n = NoteInterpolator("Clocks27",
        [a_note("G4"), a_note("C5"), a_note("D5"), a_note("E5"), a_note("F5"), a_note("G5")],                            # notes used during interpolation
        [ (a_note("G4"), 1), 
          (a_note("C5"), 1), (a_note("C5"), 0.5), (a_note("D5"), 0.5),
          (a_note("E5"), 1), (a_note("C5"), 1),
          (a_note("G5"), 1.5), (a_note("F5"), 0.5),
          (a_note("E5"), 2) ],     # note_durations
        [ 30, 64, 90 ],            # vel
        [ 1 ],         # strettos
        None,                         # midi obj
        6)
  print n.notes