Пример #1
0
    def test_in_ports(self):
        ports = ['foo', 'bar', 'baz']
        config(in_ports = ports)
        self.assertEqual(engine.in_ports(), ports)

        config(in_ports = 3)
        self.assertEqual(engine.in_ports(), ['in_0', 'in_1', 'in_2'])
Пример #2
0
    def __call__(self, ev):
        # lazy import to avoid problems with circular imports
        from mididings import engine

        # get list of port names to be used (delayed 'til first use,
        # because the engine doesn't yet exist during __init__)
        if self.ports is None:
            if self.portnames == 'in':
                self.ports = engine.in_ports()
            elif self.portnames == 'out':
                self.ports = engine.out_ports()
            else:
                self.ports = []

        # find maximum port name length (delayed for the same reason as above)
        if _Print.portnames_used and _Print.max_portname_length == -1:
            all_ports = engine.in_ports() + engine.out_ports()
            _Print.max_portname_length = max(len(p) for p in all_ports)

        if self.name:
            namestr = '%-*s ' % (_Print.max_name_length + 1, self.name + ':')
        elif _Print.max_name_length != -1:
            # no name, but names used elsewhere, so indent appropriately
            namestr = ' ' * (_Print.max_name_length + 2)
        else:
            namestr = ''

        if ev.type == _constants.SYSEX:
            eventmax = _misc.get_terminal_size()[1] - len(namestr)
        else:
            eventmax = 0
        eventstr = ev.to_string(self.ports, _Print.max_portname_length,
                                eventmax)

        print('%s%s' % (namestr, eventstr))
Пример #3
0
    def __call__(self, ev):
        # lazy import to avoid problems with circular imports
        from mididings import engine

        # get list of port names to be used (delayed 'til first use,
        # because the engine doesn't yet exist during __init__)
        if self.ports is None:
            if self.portnames == 'in':
                self.ports = engine.in_ports()
            elif self.portnames == 'out':
                self.ports = engine.out_ports()
            else:
                self.ports = []

        # find maximum port name length (delayed for the same reason as above)
        if _Print.portnames_used and _Print.max_portname_length == -1:
            all_ports = engine.in_ports() + engine.out_ports()
            _Print.max_portname_length = max(len(p) for p in all_ports)

        if self.name:
            namestr = '%-*s ' % (_Print.max_name_length + 1, self.name + ':')
        elif _Print.max_name_length != -1:
            # no name, but names used elsewhere, so indent appropriately
            namestr = ' ' * (_Print.max_name_length + 2)
        else:
            namestr = ''

        if ev.type == _constants.SYSEX:
            eventmax = _misc.get_terminal_size()[1] - len(namestr)
        else:
            eventmax = 0
        eventstr = ev.to_string(self.ports, _Print.max_portname_length,
                                eventmax)

        print('%s%s' % (namestr, eventstr))
Пример #4
0
    def sphere(self, path, args):
        """
        0 -> Main droite
        1 -> Main Gauche
        """
        note_name = args[0]
        hands = args[1]
        probability = args[2]
        force = args[3]
        
        print "got sphere : %s '%s', %d, %f, %f" % (path, 
                                                    note_name, 
                                                    hands, 
                                                    probability,
                                                    force)

        bowls = {'c2': (0, 127),
                 'd2': (0, 127)}

        speed_min = 0
        speed_max = 1

        try:
            bowl_lower = bowls[note_name][0]
            bowl_upper = bowls[note_name][1]
        except KeyError:
            bowl_lower = 0
            bowl_upper = 127

        bowl_range = bowl_upper - bowl_lower
        step = float(speed_max) / bowl_range

        print step, bowl_range
        
        midi_vel = int(min(math.ceil(bowl_lower + (float(force*force + 0.1) / step) + 5), 127))

        print midi_vel

        if hands == RIGHT_HAND:
            engine._TheEngine().process(NoteOnEvent(engine.in_ports()[0],
                                                    settings.MIDI_HAMMER_CHANNEL,
                                                    note_number(note_name),
                                                    midi_vel)
                                        )

        elif hands == LEFT_HAND:
            engine._TheEngine().process(NoteOnEvent(engine.in_ports()[0],
                                                    settings.MIDI_REPEAT_CHANNEL,
                                                    note_number(note_name),
                                                    midi_vel)
                                        )
Пример #5
0
 def hit_tempo(note, speed):
     while context['hold_repeat']:
         engine._TheEngine().process(NoteOnEvent(engine.in_ports()[0], 
                                                 settings.MIDI_HAMMER_CHANNEL, 
                                                 note, 
                                                 95)
                                     )
         time.sleep(1.35-(speed*0.010))
Пример #6
0
    def touch(self, path, args):
        name = args[0]

        if name == "head":
            print "got head"
            engine._TheEngine().process(AftertouchEvent(engine.in_ports()[0],
                                                        settings.MIDI_HAMMER_CHANNEL,
                                                        127)
                                       )
Пример #7
0
 def left_hand_pointing(self, path, args):
     note = args[0]
     if note == "":
         note = "c2"
     engine._TheEngine().process(NoteOffEvent(engine.in_ports()[0],
                                              settings.MIDI_REPEAT_CHANNEL,
                                              note,
                                              127)
                                 )
Пример #8
0
 def one_hand_gesture(self, path, args):
     name = args[0]
     if name == 'throwR':
         print "Got THROWR"
         engine._TheEngine().process(CtrlEvent(engine.in_ports()[0],
                                               settings.MIDI_HAMMER_CHANNEL, 
                                               LOWER_OCTAVE, # modwheel
                                               int(args[2])+20, # value
                                               )
                                     )
     else:
         print "Got Unknown Gesture"
Пример #9
0
 def two_hands_gesture(self, path, args):
     """
     name, force, xyz_r, xyz_l
     """
     name = args[0]
     if name == 'chord':
         # proba, force, position (R, L)
         print "Got Chord"
         engine._TheEngine().process(PitchbendEvent(engine.in_ports()[0],
                                                    1,
                                                    1)
                                     )
     print "got two hands gesture", path, args
Пример #10
0
    def play():
        for i, record in enumerate(history):
            engine._TheEngine().process(NoteOnEvent(engine.in_ports()[0], 
                                                     settings.MIDI_HAMMER_CHANNEL, 
                                                     record[0],
                                                     record[1])
                                    )

            # Wait until next note
            if i <= (len(history)-2):
                waiting = history[i+1][2] - record[2]
                
                time.sleep(waiting)

        context['history'] = []
        context['history_is_running'] = False
Пример #11
0
    def throw_glissando_note(note):
        for note in notes_to_play:
            try:
                engine._TheEngine().process(NoteOnEvent(engine.in_ports()[0], 
                                                        settings.MIDI_HAMMER_CHANNEL, 
                                                        note,
                                                        120)
                                            )
            except Exception, e:
                print "Failure during glissando"


            sleep_min = 0.012
            sleep_max = 0.216
            sleep_time = max(sleep_max - (math.log10(max(velocity, 1))  / 20.), sleep_min)
            time.sleep(sleep_time)
Пример #12
0
    def sphere_stop(self, path, args):
        sphere_name = args[0]
        print "stop sphere", sphere_name

        note = None
        for bowl in self.configs.current.bowls:
            if bowl.note.label == sphere_name:
                note = bowl.note.label
                break

        if note:
            engine._TheEngine().process(NoteOnEvent(engine.in_ports()[0],
                                                    settings.MIDI_DAMPER_CHANNEL,
                                                    note,
                                                    127)
                                        )
            print "sent stop", args
Пример #13
0
    def throw(self, path, args):
        hand = args[0]
        name = args[1]
        force = args[2]

        right_hand_evmap = {'dlur': RH_GLIS_UP,
                            'urdl': RH_GLIS_DOWN,
                            'rl': WHOLE_ALTERED,
                            'lr': INSCALE_UP,
                            'drul': RH_RAF_UP,
                            'uldr': RH_RAF_DOWN
                            }

        left_hand_evmap = {'dlur': LH_GLIS_UP,
                           'urdl': LH_GLIS_DOWN,
                           'uldr': LH_RAF_DOWN,
                           'drul': LH_RAF_UP,
                           'lr': WHOLE_NORMAL,
                           'rl': INSCALE_DOWN,
                           }

        if hand == LEFT_HAND:
            midi_event = left_hand_evmap[name]
        elif hand == RIGHT_HAND:
            midi_event = right_hand_evmap[name]
        else:
            midi_event = -1
            print "PROBLEM !!"

        step = 1.0 / 127
        midi_vel = int(min(math.floor(float(force*0.75 + 0.001) / step), 127))
        
        print ">>>>> throwing", name, force, midi_vel
        
        engine._TheEngine().process(CtrlEvent(engine.in_ports()[0],
                                              settings.MIDI_HAMMER_CHANNEL, 
                                              midi_event, # modwheel
                                              midi_vel, # value
                                              )
                                    )
Пример #14
0
 def throw_damper_release_note(note):
     engine._TheEngine().process(NoteOffEvent(engine.in_ports()[0], 
                                              settings.MIDI_DAMPER_CHANNEL, 
                                              note, 
                                              127)
                                 )
Пример #15
0
 def trigger(self):
     engine._TheEngine().process(NoteOnEvent(engine.in_ports()[0],
                                             1,
                                             note_number(self.note.label),
                                             127))
Пример #16
0
 def stopall(self, path, args):
     engine._TheEngine().process(CtrlEvent(engine.in_ports()[0],
                                           settings.MIDI_DAMPER_CHANNEL,
                                           123,
                                           0)
                                 )