Exemple #1
0
    def __init__(self, hyperion, mod_num, *a, **kw):
        super(HyperionChan, self).__init__(*a, **kw)

        self.hyperion = hyperion
        self.mod_num = mod_num

        self._track_selector_encoder = EncoderElement(MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 0x15, Live.MidiMap.MapMode.relative_smooth_binary_offset) # Right encoder on Hyperion
        self._track_selector_encoder.add_value_listener(self._on_track_selector_encoder)

        self._fader = SliderElement(MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 0x25)
        self._pots = [
            EncoderElement(MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 0x1E + num, Live.MidiMap.MapMode.absolute, name='Pot{}'.format(num))
            for num in range(8)
        ]
        self._btns = [
            ButtonElement(True, MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 1 + num, name='Btn{}'.format(num))
            for num in range(8)
        ]
        self._enc_right_btn = ButtonElement(True, MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 10, name='EncRightBtn')
        self._enc_right_btn.add_value_listener(self._on_enc_right_btn)

        #self._cs = ChannelStripComponent()
        #self._cs.set_volume_control(self._fader)
        self._vu_slider = SliderElement(MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 60)

        self._vu = VUMeter(self)

        self._track = None

        tracks = self._get_all_tracks(self.hyperion.song().tracks)
        if len(tracks) > self.mod_num:
            self._bind_to_track(tracks[self.mod_num])
        else:
            self._bind_to_track(None)
Exemple #2
0
class HyperionChan(CompoundComponent):
    def __init__(self, hyperion, mod_num, *a, **kw):
        super(HyperionChan, self).__init__(*a, **kw)

        self.hyperion = hyperion
        self.mod_num = mod_num

        self._track_selector_encoder = EncoderElement(MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 0x15, Live.MidiMap.MapMode.relative_smooth_binary_offset) # Right encoder on Hyperion
        self._track_selector_encoder.add_value_listener(self._on_track_selector_encoder)

        self._fader = SliderElement(MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 0x25)
        self._pots = [
            EncoderElement(MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 0x1E + num, Live.MidiMap.MapMode.absolute, name='Pot{}'.format(num))
            for num in range(8)
        ]
        self._btns = [
            ButtonElement(True, MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 1 + num, name='Btn{}'.format(num))
            for num in range(8)
        ]
        self._enc_right_btn = ButtonElement(True, MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 10, name='EncRightBtn')
        self._enc_right_btn.add_value_listener(self._on_enc_right_btn)

        #self._cs = ChannelStripComponent()
        #self._cs.set_volume_control(self._fader)
        self._vu_slider = SliderElement(MIDI_CC_TYPE, MIDI_MASTER_CH + 1 + mod_num, 60)

        self._vu = VUMeter(self)

        self._track = None

        tracks = self._get_all_tracks(self.hyperion.song().tracks)
        if len(tracks) > self.mod_num:
            self._bind_to_track(tracks[self.mod_num])
        else:
            self._bind_to_track(None)

    def log(self, msg, *args):
        self.hyperion.log_message(('HyperionChan({}): ' + msg).format(self.mod_num, *args))

    def disconnect(self):
        super(HyperionChan, self).disconnect()

        self._enc_right_btn.remove_value_listener(self._on_enc_right_btn)

    def _get_parent_by_type(self, obj, parent_type):
        if not obj.canonical_parent:
            return
        if isinstance(obj.canonical_parent, parent_type):
            return obj.canonical_parent
        return self._get_parent_by_type(obj.canonical_parent, parent_type)

    def _on_enc_right_btn(self, value):
        if value and self._track:
            self.log('type {}',type(self._track))

            song = self.hyperion.song()
            if isinstance(self._track, Live.Track.Track):
                song.view.selected_track = self._track
            elif isinstance(self._track, Live.DrumChain.DrumChain):
                parent_track = self._get_parent_by_type(self._track, Live.Track.Track)

                song.view.selected_track = parent_track
                try:
                    song.view.selected_chain = self._track
                except:
                    try:
                        song.view.selected_track = parent_track
                        song.view.selected_chain = self._track.canonical_parent.canonical_parent
                        self._track.canonical_parent.view.selected_chain = self._track
                    except:
                        pass

    def _get_track_mapper_device(self, track):
        for device in track.devices:
            if device.name == 'MultiMapper16 V2.0':
                return device

    def _get_all_tracks(self, all_tracks):
        got_tracks = []

        for cur_track in all_tracks:
            if isinstance(cur_track, (Live.Track.Track, Live.DrumChain.DrumChain)):
                got_tracks.append(cur_track)

            devices = list(cur_track.devices)
            if len(devices) and isinstance(devices[0], Live.RackDevice.RackDevice):
                got_tracks.extend(self._get_all_tracks(devices[0].chains))

        return [track for track in got_tracks if self._get_track_mapper_device(track)]

    def _on_track_selector_encoder(self, value):
        direction = 1 if value > 64 else -1

        tracks = self._get_all_tracks(self.hyperion.song().tracks)

        # for t in tracks:
        #     self.log('AAAAA {}', t.name)

        try:
            cur_track_idx = tracks.index(self._track)
        except ValueError:
            self.log('track disappeared :(')
            self._bind_to_track(tracks[0])
        else:
            cur_track_idx += direction
            if cur_track_idx == len(tracks):
                cur_track_idx = 0
            if cur_track_idx == -1:
                cur_track_idx = len(tracks) - 1
            self._bind_to_track(tracks[cur_track_idx])

    def _bind_to_track(self, track):
        if self._track:
            #self._cs.set_track(None)
            self._fader.release_parameter()
            [pot.release_parameter() for pot in self._pots]
            [btn.release_parameter() for btn in self._btns]

            self._track.remove_name_listener(self._on_name_changed)

            self._track = None

        if not track:
            return

        self.log('binding to {}', track.name)
        self._track = track

        self._fader.connect_to(track.mixer_device.volume)

        mapper_dev = self._get_track_mapper_device(track)
        for num in range(8):
            self._pots[num].connect_to(mapper_dev.parameters[3 + num]) # MacroA0 MacroA1 etc
            self._btns[num].connect_to(mapper_dev.parameters[11 + num]) # MacroB0 MacroB1 etc

        # self._cs.set_track(track)

        if getattr(self._track, 'has_audio_output', False) and hasattr(self._track, 'add_output_meter_left_listener'):
            self._vu.set_vu_meter(track, self._vu_slider)
        else:
            self._vu.set_vu_meter(None, None)

        self._track.add_name_listener(self._on_name_changed)
        self._on_name_changed()

    def _on_name_changed(self):
        self.hyperion.sysex.set_title(self.mod_num, self._track.name if self._track else '-')
Exemple #3
0
#! /ufs/guido/bin/sgi/python

import audio
import stdwin

from VUMeter import VUMeter
from WindowParent import WindowParent
import MainLoop

NBUFS=20
BUFSIZE = NBUFS*48
SCALE=128

class MyVUMeter() = VUMeter():
       def init_reactivity(self):
               self.parent.need_mouse(self)
       def mouse_down(self, detail):
               if self.enabled:
                       self.stop()
               else:
                       self.start()
       def mouse_move(self, detail): pass
       def mouse_up(self, detail): pass

def main():
       audio.setrate(3)
       audio.setoutgain(0)
       w = WindowParent().create('VU Meter', (200, 100))
       v = MyVUMeter().define(w)
       v.start()
       w.realize()
Exemple #4
0
 def _create_vu_meter(self):
     return VUMeter(self)
Exemple #5
0
 if args:
         G.savefile = args[0]
 #
 # Initialize the sound package
 #
 audio.setoutgain(G.nomuting * G.gain)   # Silence the speaker
 audio.setrate(G.rate)
 #
 # Create the WindowParent and VSplit
 #
 G.window = WindowParent().create('Recorder', (0, 0))
 w = G.vsplit = VSplit().create(G.window)
 #
 # VU-meter
 #
 G.vubtn = VUMeter().define(w)
 #
 # Radiobuttons for rates
 #
 r1btn = RadioButton().definetext(w, '32 K/sec')
 r1btn.on_hook = rate_hook
 r1btn.rate = 1
 #
 r2btn = RadioButton().definetext(w, '16 K/sec')
 r2btn.on_hook = rate_hook
 r2btn.rate = 2
 #
 r3btn = RadioButton().definetext(w, '8 K/sec')
 r3btn.on_hook = rate_hook
 r3btn.rate = 3
 #
Exemple #6
0
def main():
    #
    # Turn off scroll bars
    #
    stdwin.setdefscrollbars(0, 0)
    #
    # Set default state
    #
    G.gain = 60
    G.rate = 3
    G.nomuting = 0
    G.savefile = '@rec'
    #
    # Set default values
    #
    G.data = ''
    G.playing = 0
    G.recording = 0
    G.sogram = 0
    #
    # Parse options
    #
    optlist, args = getopt.getopt(sys.argv[1:], 'mdg:r:')
    #
    for optname, optarg in optlist:
        if 0:  # (So all cases start with elif)
            pass
        elif optname == '-d':
            G.debug = 1
        elif optname == '-g':
            G.gain = string.atoi(optarg)
            if not (0 < G.gain < 256):
                raise optarg.error, '-g gain out of range'
        elif optname == '-m':
            G.nomuting = (not G.nomuting)
        elif optname == '-r':
            G.rate = string.atoi(optarg)
            if not (1 <= G.rate <= 3):
                raise optarg.error, '-r rate out of range'
    #
    if args:
        G.savefile = args[0]
    #
    # Initialize the sound package
    #
    audio.setoutgain(G.nomuting * G.gain)  # Silence the speaker
    audio.setrate(G.rate)
    #
    # Create the WindowParent and VSplit
    #
    G.window = WindowParent().create('Recorder', (0, 0))
    w = G.vsplit = VSplit().create(G.window)
    #
    # VU-meter
    #
    G.vubtn = VUMeter().define(w)
    #
    # Radiobuttons for rates
    #
    r1btn = RadioButton().definetext(w, '32 K/sec')
    r1btn.on_hook = rate_hook
    r1btn.rate = 1
    #
    r2btn = RadioButton().definetext(w, '16 K/sec')
    r2btn.on_hook = rate_hook
    r2btn.rate = 2
    #
    r3btn = RadioButton().definetext(w, '8 K/sec')
    r3btn.on_hook = rate_hook
    r3btn.rate = 3
    #
    radios = [r1btn, r2btn, r3btn]
    r1btn.group = r2btn.group = r3btn.group = radios
    for r in radios:
        if r.rate == G.rate: r.select(1)
    #
    # Other controls
    #
    G.recbtn = TimeOutToggleButton().definetext(w, 'Record')
    G.recbtn.on_hook = record_on_hook
    G.recbtn.timer_hook = record_timer_hook
    G.recbtn.off_hook = record_off_hook
    #
    G.mutebtn = CheckButton().definetext(w, 'Mute')
    G.mutebtn.select(not G.nomuting)
    G.mutebtn.hook = mute_hook
    #
    G.playbtn = TimeOutToggleButton().definetext(w, 'Playback')
    G.playbtn.on_hook = play_on_hook
    G.playbtn.timer_hook = play_timer_hook
    G.playbtn.off_hook = play_off_hook
    #
    G.gainbtn = ComplexSlider().define(w)
    G.gainbtn.settexts('  Volume: ', '  ')
    G.gainbtn.setminvalmax(0, G.gain, 255)
    G.gainbtn.sethook(gain_hook)
    #
    G.sizebtn = Label().definetext(w, ` len(G.data) ` + ' bytes')
    #
    #G.showbtn = PushButton().definetext(w, 'Sound-o-gram...')
    #G.showbtn.hook = show_hook
    #
    G.savebtn = PushButton().definetext(w, 'Save...')
    G.savebtn.hook = save_hook
    #
    G.quitbtn = PushButton().definetext(w, 'Quit')
    G.quitbtn.hook = quit_hook
    G.playbtn.enable(0)
    G.savebtn.enable(0)
    #G.showbtn.enable(0)
    start_vu()
    G.window.realize()
    #
    # Event loop
    #
    MainLoop()