Example #1
0
    def init(self, channel=0, port_name='nfb'):
        from rtmidi2 import MidiOut
        self.channel = channel
        self.midi = MidiOut().open_virtual_port(port_name)

        self.config_button = QtGui.QToolButton()
        self.config_button.clicked.connect(self.config_dialog)
        self.config_button.block = self

        self.config = False
Example #2
0
class MidiControl(Block):
    cc = Dict(Range(0, 127), Input)

    def init(self, channel=0, port_name='nfb'):
        from rtmidi2 import MidiOut
        self.channel = channel
        self.midi = MidiOut().open_virtual_port(port_name)

        self.config_button = QtGui.QToolButton()
        self.config_button.clicked.connect(self.config_dialog)
        self.config_button.block = self

        self.config = False

        #self.on_trait_change()
        #self.config_dialog()

    def config_dialog(self):
        self.config = True
        win = QtGui.QDialog()

        layout = QtGui.QVBoxLayout()

        keys = self.cc.keys()
        keys.sort()

        for cc in keys:
            label = "CC " + str(cc)
            button = QtGui.QPushButton(label)
            func = lambda cc=cc: self.midi.send_cc(0, cc, random.randint(0, 127))
            button.pressed.connect(func)
            layout.addWidget(button)

        finishButton = QtGui.QPushButton('Finished')
        layout.addWidget(finishButton)
        finishButton.clicked.connect(win.accept)

        win.setLayout(layout)

        win.exec_()
        self.config = False

    def updateGUI(self):
        if self.config: return

        clamp = lambda x, mi, ma: max(min(ma, x), mi)
        for cc in self.cc:
            sig = self.cc[cc]
            val = clamp(sig.buffer[-1] * 127, 0, 127)

            self.midi.send_cc(0, cc, val)
        #self.midi.send_pitchbend(0, random.random() * 8000)

    def widget(self):
        return self.config_button
Example #3
0
class MIDIDrum(Block):
    pitch = Input(default=440)
    velocity = Input(default=1.0)
    trigger = Input()

    def init(self, channel=0, port_name='drum'):
        from rtmidi2 import MidiOut
        self.channel = channel
        self.midi = MidiOut().open_virtual_port(port_name)

    def process(self):
        if self.trigger.posedge:
            pitch = self.pitch
            vel = self.velocity
            if not pitch:
                pitch = 100
            if not vel:
                vel = 1.0
            self.midi.send_noteon(self.channel, pitch, vel)
Example #4
0
class MIDIDrum(Block):
    pitch = Input(default=440)
    velocity = Input(default=1.0)
    trigger = Input()

    def init(self, channel=0, port_name='drum'):
        from rtmidi2 import MidiOut
        self.channel = channel
        self.midi = MidiOut().open_virtual_port(port_name)

    def process(self):
        if self.trigger.posedge:
            pitch = self.pitch
            vel = self.velocity
            if not pitch:
                pitch = 100
            if not vel:
                vel = 1.0
            self.midi.send_noteon(self.channel, pitch, vel)
Example #5
0
 def init(self, channel=0, port_name='drum'):
     from rtmidi2 import MidiOut
     self.channel = channel
     self.midi = MidiOut().open_virtual_port(port_name)
Example #6
0
 def init(self, channel=0, port_name='drum'):
     from rtmidi2 import MidiOut
     self.channel = channel
     self.midi = MidiOut().open_virtual_port(port_name)