Example #1
0
def main( argv ):
	pypm.Initialize()
	deviceInput = None
	deviceOutput = None
	blockAddress = None
	latency = 0
	try:
		opts, args = getopt.getopt( argv, "i:o:b:", [ "input=", "output=", "blockAddress=" ] )
		for opt, arg in opts:
			if opt in ( "-i", "--input" ):
				deviceInput = arg
			elif opt in ( "-o", "--output" ):
				deviceOutput = arg
			elif opt in ( "-b", "--blockAddress" ):
				blockAddress = arg
		if deviceInput == None or deviceOutput == None or blockAddress == None:
			usage()
			sys.exit( 2 )
	except getopt.GetoptError:
		usage()
		sys.exit( 2 )

	SysexTest( deviceInput, deviceOutput, blockAddress, latency )

	pypm.Terminate()
Example #2
0
    def run(self):
        self.running = True
        pypm.Initialize()
        self.in_device = pypm.Input(self.in_device_id)
        self.out_device = pypm.Output(self.out_device_id)

        self.clear()

        #    try:
        #      while self.running:
        #        self.read_buttons()
        #    finally:
        #      print("Shutting down.")
        #      self.in_device.Close()
        #      self.out_device.Close()
        #      pypm.Terminate()
        #
        #    return

        try:
            while self.running:
                self.set_pattern(0)
                time.sleep(self.wait)
                self.set_pattern(1)
                time.sleep(self.wait)

        finally:
            print("Shutting down.")
            self.clear()
            self.in_device.Close()
            self.out_device.Close()
            pypm.Terminate()
Example #3
0
    def __init__(self, device_out=0, channel_out=1, device_in=0, channel_in=1):
        ioflow.TWidget.__init__(self,
                                name="midi",
                                label="Midi Widget",
                                category="test")
        pypm.Initialize()

        self.device_out = int(device_out)
        self.channel_out = int(channel_out)
        self.device_in = int(device_in)
        self.channel_in = int(channel_in)

        self._midi_out = pypm.Output(self.device_out, 20)

        self.add_pad(
            ioflow.TPad(label="Midi Note",
                        value=0,
                        flow="in",
                        min=0,
                        max=127,
                        listener=self.play_note))

        self.add_pad(
            ioflow.TPad(label="Volume Control",
                        value=0,
                        flow="in",
                        min=0,
                        max=127,
                        listener=self.volume_control))
Example #4
0
 def __init__(self, parent, device, notes, cc):
     pypm.Initialize()
     pypm.CountDevices()
     self.MidiIn = pypm.Input(device)
     self.parent = parent
     self.notes = notes
     self.cc = cc
Example #5
0
 def initialize(self):
     pypm.Initialize()
     midiOutput = self.selectFirebox()
     if (midiOutput >= 0):
         self.MidiOut = pypm.Output(midiOutput, latency)
         return True
     else:
         print "Couldn't select Firebox."
         return False
Example #6
0
 def initialize(cls):
     """
     Initialize pypm if not already initialized.
     """
     if cls.initialized:
         return
     pypm.Initialize()
     cls._gatherDeviceInfo()
     cls.initialized = True
Example #7
0
    def __init__(self):
        pypm.Initialize()
        self.midi = None
        self.debug = False

        for n in range(pypm.CountDevices()):
            info = pypm.GetDeviceInfo(n)
            name = info[1]
            isOutput = info[3]
            if name == MIDIOUT_DEFAULT and isOutput == 1:
                self.midi = pypm.Output(n, 1)
                print "Found MIDI output (%s)" % name
Example #8
0
    def __init__(self, target=MIDIIN_DEFAULT):
        pypm.Initialize()
        self.midi = None

        for n in range(pypm.CountDevices()):
            info = pypm.GetDeviceInfo(n)
            name = info[1]
            print "[%d] %s %s" % (n, name, info)
            isInput = info[2]
            if name == target and isInput == 1:
                self.midi = pypm.Input(n)
                print "found target input: %s" % target

        if self.midi is None:
            raise Exception, "Could not find MIDI source: %s" % target
Example #9
0
def main():
    a = ScorePhrase()
    a.addEvent(SE(60, 127, 0))
    a.addEvent(SE(55, 127, 9))
    a.addEvent(SE(52, 127, 18))
    a.addEvent(SE(57, 127, 27))
    a.addEvent(SE(59, 127, 33))
    a.addEvent(SE(57, 127, 39))
    a.addEvent(SE(56, 127, 42))

    track1 = ScoreTrack()
    track1.addPhrase(a, 0)
    track1.setMidiChannel(1)
    track1.setMidiTranspose(12)

    player = Player()
    player.addTrack(track1)

    #initialize midi
    pypm.Initialize()
    m = pypm.Output(0, 0)
    m.WriteShort(0xB0, 99, 1)
    m.WriteShort(0xB0, 74, 51)
    m.WriteShort(0xB0, 11, 82)
    m.WriteShort(0xB0, 75, 80)
    m.WriteShort(0xB0, 77, 72)
    m.WriteShort(0xB0, 71, 73)

    bpm = 120
    deltat = 60000.0 / bpm / 4 / 4
    print deltat
    # for 2 bars
    for b in range(2):
        # for all 48 PPQN events
        for t in range(0, 47, 1):
            # for all tracks in the player
            for z in player.tracks:
                events = z.getMidiAt(b, t)
                if (events != None):
                    print("midi events on track [ %s ] at %d,%d: %s") % (
                        z.getName(), b, t, events)
                    n = events[0]
                    if (n != None):
                        m.WriteShort(n[0], n[1], n[2])
            msleep(deltat)
Example #10
0
def main(config):
    pypm.Initialize()
    if config.device:
        d = find_device(config.device)
    else:
        d = (config.indevice, config.outdevice)
    if not d is None or not (d[0] is None or d[1] is None):
        #    try:
        #      in_device = pypm.Input(d[0])
        #    except:
        #      print("Error: Could not open input device.")
        #      pypm.Terminate()
        #      return
        #
        #    try:
        #      out_device = pypm.Output(d[1])
        #    except:
        #      print("Error: Could not open output device.")
        #      pypm.Terminate()
        #      return
        print d
        uidriver = MidiDriver(d[0], d[1])
        if config.verbose:
            uidriver = DebugDriver(uidriver)

        try:
            time.sleep(2)
            print 'Life()'
            life = Life(uidriver)
            print 'run()'
            life.run(1)
            print 'Done.'
        except Exception as e:
            traceback.print_exc()
        finally:
            uidriver.clear()
            uidriver.close()
            pypm.Terminate()
            return
    else:
        print 'No input/output device found.  Exiting.'
Example #11
0
 def __init__(self, port_number):
     super(MidiTest, self).__init__()
     pypm.Initialize()
     self.output = pypm.Output(port_number, 0)
Example #12
0
(output only at the moment)

@TODO: move everything to PyPortMidi
"""

import sys
import CoreMIDI
if sys.platform == "darwin":
    device = CoreMIDI

    def tick():
        pass

elif sys.platform == "win32":
    import pypm
    pypm.Initialize()

    class PyPortMidiDevice(object):
        def __init__(self):
            self.outd = pypm.Output(0, 0)
            self.ind = pypm.Input(1)  #@TODO: select from dropdown.
            self.pyCallback = lambda a, b, c: None  # do nothing
            self.echo = True

        def tick(self):
            while self.ind.Poll():
                (a, b, c, d), time = self.ind.Read(1)[0]
                self.pyCallback((a, b, c))
                if self.echo:
                    self.send(a, b, c)
Example #13
0
def init():
    global _initialized
    if not _initialized:
        pypm.Initialize()
        _initialized = True
 def init_module(self):
     pyportmidi.Initialize()
Example #15
0
 def __init__(self, pattern=Pattern()):
     pypm.Initialize()
     self.bpm = 120
     self.pattern = pattern
     self.output = pypm.Output(pypm.GetDefaultOutputDeviceID(), LATENCY)
Example #16
0
def main2():
    p = Player()
    a = AutomationTrack()
    s = ScoreTrack()

    s1 = ScorePhrase()
    s2 = ScorePhrase()
    s.addPhrase(s1, 0)
    s.addPhrase(s2, 1)
    s.setMidiTranspose(-12)

    # lead thing
    b = 12 * 6
    s1.addEvent(SE(b, 127, 0))
    s1.addEvent(SE(b, 127, 6))
    s1.addEvent(SE(b + 7, 127, 12))
    s1.addEvent(SE(b + 7, 127, 18))
    s1.addEvent(SE(b + 9, 127, 24))
    s1.addEvent(SE(b + 9, 127, 30))
    s1.addEvent(SE(b + 7, 127, 36))

    s2.addEvent(SE(b + 5, 127, 0))
    s2.addEvent(SE(b + 5, 127, 6))
    s2.addEvent(SE(b + 4, 127, 12))
    s2.addEvent(SE(b + 4, 127, 18))
    s2.addEvent(SE(b + 2, 127, 24))
    s2.addEvent(SE(b + 2, 127, 30))
    s2.addEvent(SE(b + 0, 127, 36))

    # automations
    a1 = AutomationPhrase()
    a.setMidiChannel(1)
    a.setCC(64)
    a1.addEvent(AE(0, 0))
    a1.addEvent(AE(127, 24))
    a.addPhrase(a1, 0)
    a.addPhrase(a1, 1)

    p.addTrack(a)
    p.addTrack(s)

    s.getLastBar()
    #p.debug_ShowMidiDevices()
    #return
    pypm.Initialize()
    m = pypm.Output(0, 0)
    m.WriteShort(0xB0, 99, 1)
    #m.WriteShort(0xB0, 52, 1)
    #m.WriteShort(0xB0, 71, 64)
    #m.WriteShort(0xB0, 76, 1)

    print "a=", a.getMidiAt(0, 0)
    print "s=", s.getMidiAt(0, 0)
    print "a=", a.getMidiAt(0, 24)
    print "s=", s.getMidiAt(0, 24)

    # for 2 bars
    for b in range(2):
        # for all 48 PPQN events
        for t in range(0, 47, 6):
            # for all tracks in the player
            for z in p.tracks:
                events = z.getMidiAt(b, t)
                if (events != None):
                    print("midi events on track [ %s ] at %d,%d: %s") % (
                        z.getName(), b, t, events)
                    n = events[0]
                    if (n != None):
                        m.WriteShort(n[0], n[1], n[2])
            msleep(200)
Example #17
0
 def __init__(self):
     super(MidiHandler,self).__init__()
     self.procs   = []
     pypm.Initialize()
Example #18
0
    MidiOut.Write(ChordList)
    while pypm.Time() < MidiTime + 1000 + len(chord) * 1000 : pass
    ChordList = []
    # seems a little odd that they don't update MidiTime here...
    for i in range(len(chord)):
        ChordList.append([[0x90,chord[i],0], MidiTime + 1000 * i])
    MidiOut.Write(ChordList)
    print("Sending SysEx messages...")
    # sending with timestamp = 0 should be the same as sending with
    # timestamp = pypm.Time()
    dummy = raw_input("ready to send a SysEx string with timestamp = 0 ... (type RETURN):")
    MidiOut.WriteSysEx(0,'\xF0\x7D\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\xF7')
    dummy = raw_input("ready to send a SysEx list with timestamp = pypm.Time() ... (type RETURN):")
    MidiOut.WriteSysEx(pypm.Time(), [0xF0, 0x7D, 0x10, 0x11, 0x12, 0x13, 0xF7])
    dummy = raw_input("ready to close and terminate... (type RETURN):")
    del MidiOut

# main code begins here
pypm.Initialize() # always call this first, or OS may crash when you try to open a stream
x=0
while (x<1) | (x>2):
    print """
enter your choice...
1: test input
2: test output
    """
    x=int(raw_input())
    if x==1: TestInput()
    else: TestOutput()
    pypm.Terminate()