├── assignment_01.png ├── BeatStep_Q_Overlay.png ├── _config.yml ├── __init__.py ├── BaseComponent.py ├── QSetup.py ├── BeatStep_Q.py ├── README.md ├── QBrowser.py ├── QSequencer.py └── LICENSE /assignment_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raphaelquast/beatstep/HEAD/assignment_01.png -------------------------------------------------------------------------------- /BeatStep_Q_Overlay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raphaelquast/beatstep/HEAD/BeatStep_Q_Overlay.png -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate 2 | title: BeatStep + Ableton Live 3 | markdown: CommonMarkGhPages 4 | gems: 5 | - jemoji -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | # Embedded file name: /Users/versonator/Jenkins/live/output/Live/mac_64_static/Release/python-bundle/MIDI Remote Scripts/BeatStep_Q/__init__.py 2 | from __future__ import absolute_import, print_function, unicode_literals 3 | import _Framework.Capabilities as caps 4 | from .BeatStep_Q import BeatStep_Q 5 | 6 | 7 | def get_capabilities(): 8 | return { 9 | caps.CONTROLLER_ID_KEY: caps.controller_id( 10 | vendor_id=7285, product_ids=[518], model_name=["Arturia BeatStep"] 11 | ), 12 | caps.PORTS_KEY: [ 13 | caps.inport(props=[caps.NOTES_CC, caps.SCRIPT, caps.REMOTE]), 14 | caps.outport(props=[caps.SCRIPT]), 15 | ], 16 | } 17 | 18 | 19 | def create_instance(c_instance): 20 | return BeatStep_Q(c_instance) 21 | -------------------------------------------------------------------------------- /BaseComponent.py: -------------------------------------------------------------------------------- 1 | from functools import partial 2 | 3 | 4 | class BaseComponent(object): 5 | '''base class for track-based assignments 6 | 7 | any provided buttonname will get a setter and listener assigned as follows: 8 | self._button # the button element 9 | self._listener # if defined, this listener will be assigned to the button as a value-listener 10 | self.set__button # a setter-function to set the button 11 | 12 | ''' 13 | __module__ = __name__ 14 | 15 | def __init__(self, parent, buttonnames=[]): 16 | self._parent = parent 17 | 18 | self._buttonnames = buttonnames 19 | 20 | # define setter functions "set_button()" for all required buttons 21 | # and assign the listeners "button_listener(value)" accordingly 22 | for name in self._buttonnames: 23 | buttonname = name + '_button' 24 | listener = name + '_listener' 25 | setter = 'set' + buttonname 26 | 27 | # set all buttons to None 28 | setattr(self, buttonname, None) 29 | # define setter functions 30 | setattr(self, setter, 31 | partial(self._set_a_button, name=buttonname, 32 | listener=listener)) 33 | 34 | 35 | def _set_a_button(self, button, name, listener): 36 | ''' 37 | a generic setter function for the buttons 38 | ''' 39 | listener_func = getattr(self, listener, None) 40 | assigned_button = getattr(self, name, None) 41 | 42 | # only if button is not yet assigned 43 | if assigned_button != button: 44 | if listener_func != None: 45 | if listener != None and button != None: 46 | # remove existing listener 47 | button.remove_value_listener(listener_func) 48 | button.add_value_listener(listener_func) 49 | # set the button 50 | setattr(self, name, button) 51 | else: 52 | # just set the button 53 | setattr(self, name, button) -------------------------------------------------------------------------------- /QSetup.py: -------------------------------------------------------------------------------- 1 | # thanks to https://www.untergeek.de/de/2014/11/taming-arturias-beatstep-sysex-codes-for-programming-via-ipad/#Sysex_for_the_Pads 2 | # for unravelling sysx messages for BeatStep 3 | 4 | 5 | class QSetup(object): 6 | """ 7 | ##### BUTTON 8 | set_B_......... (ID, val) 9 | ID: the button number (1-16), or one of ('play', 'stop', 'cntrl', 'sync', 'recall', 'store', 'shift', 'chan') 10 | 11 | mode: set button mode 12 | (0=off, 1=silent, 2=silent cc switch, 7=mmc, 8=cc, 9=note) 13 | channel: set midi channel 14 | (0-15) (65 to follow the global channel) 15 | cc: set midi CC 16 | (0-127) 17 | off: set midi off value 18 | (0-127) 19 | on: set midi on value 20 | (0-127) 21 | behaviour: set button behaviour 22 | (0=toggle, 1=gate) 23 | color: set button LED color [only works if button is set to note] 24 | (0=black, 1=red, 16=blue, 17=magenta) 25 | 26 | set_B_velocity(value): set button velocity curve (global) 27 | (0=linear, 1=logarithmic, 2=exponential, 3=full) 28 | 29 | ##### ENCODER 30 | set_E_......... (ID, val) 31 | ID: the encoder number (1-16) 32 | 33 | mode: set encoder mode 34 | (0=off, 1=Midi cc, 4=RPN/NRPN) 35 | channel: set midi channel 36 | (0-15) (65 to follow the global channel) 37 | cc: set midi CC 38 | (0-127) 39 | off: set lowest possible value [only if encoder is set to absolute] 40 | (0-127) 41 | on: set highest possible value [only if encoder is set to absolute] 42 | (0-127) 43 | behaviour set encoder behaviour 44 | (0=absolute, 1-3=relative mode 1-3) 45 | 46 | set_E_acceleration(value): set encoder acceleration (global) 47 | (0=slow, 1=medium, 2=fast) 48 | 49 | ##### SEQUENCER 50 | set_S_...(val) 51 | mode: set the mode 52 | (0=forward, 1=reverse, 2=alternating, 3=random) 53 | channel: set midi channel 54 | (0-15) 55 | rate: set rate (e.g. speed) 56 | (0-4) 57 | transpose: base note is C5=60, to transpose down 12 semitones to C4, nn=48 and so on 58 | (0-127) 59 | scale: set the scale 60 | (0=chromatic, 1=major, 2=minor, 3=dorian, 4=mixolydian, 5=harmonic minor, 6=blues, 7=user) 61 | stepsize: set the step-size 62 | (0=1/4, 1=1/8, 2=1/16, 3=1/32) 63 | length: set pattern-length to 1-16 steps 64 | (0-15) 65 | swing: set swing 66 | (50=no swing, 75=maximal swing) 67 | gate: set gate (0-99%) 68 | (0-99) 69 | legato: set legato 70 | (0=off, 1=on, 2=reset) 71 | 72 | set_S_on(ID): turn on step 73 | (0-15) 74 | set_S_off(ID): turn off step 75 | (0-15) 76 | set_S_note(ID, val): set note (val) for step (ID) 77 | (0-15), (1-127) 78 | 79 | #### GLOBAL 80 | set_global_channel(c): set the global midi-channel 81 | (0-15) 82 | """ 83 | 84 | def __init__(self): 85 | 86 | # a dict with the button IDS 87 | self._B = dict( 88 | play=88, # white 89 | stop=89, # no light 90 | cntrl=90, # red or blue 91 | sync=91, # blue 92 | recall=92, # blue 93 | store=93, # red 94 | shift=94, # blue 95 | chan=95, # blue 96 | ) 97 | # a dict with the encoder IDS 98 | self._E = dict(transpose=48) 99 | 100 | for i in range(1, 17): 101 | self._B[i] = 111 + i 102 | self._E[i] = 31 + i 103 | 104 | self._funcdict = dict( 105 | mode=1, channel=2, cc=3, off=4, on=5, behaviour=6, color=16 106 | ) 107 | 108 | self._S_funcdict = dict( 109 | channel=1, 110 | transpose=2, 111 | scale=3, 112 | mode=4, 113 | stepsize=5, 114 | length=6, 115 | swing=7, 116 | gate=8, 117 | legato=9, 118 | ) 119 | 120 | self._B_START_MSG = ( 121 | 240, 122 | 0, 123 | 32, 124 | 107, 125 | 127, 126 | 66, 127 | 2, 128 | 0, 129 | ) # F0 00 20 6B 7F 42 02 00 c ID val F7 130 | self._B_REQUEST_MSG = ( 131 | 240, 132 | 0, 133 | 32, 134 | 107, 135 | 127, 136 | 66, 137 | 1, 138 | 0, 139 | ) # F0 00 20 6B 7F 42 01 00 c ID F7 140 | 141 | # set button and encoder getters and setters 142 | for key, c in self._funcdict.items(): 143 | funcs = self._get_callbacks(c) 144 | setattr(self, "set_B_" + key, funcs[0]) 145 | setattr(self, "get_B_" + key, funcs[1]) 146 | setattr(self, "set_E_" + key, funcs[2]) 147 | setattr(self, "get_E_" + key, funcs[3]) 148 | 149 | E_acc_set, E_acc_get = self._get_acceleration_callback() 150 | setattr(self, "set_E_acceleration", E_acc_set) 151 | setattr(self, "get_E_acceleration", E_acc_get) 152 | 153 | B_velocity_set, B_velocity_get = self._get_velocity_callback() 154 | setattr(self, "set_B_velocity", B_velocity_set) 155 | setattr(self, "get_B_velocity", B_velocity_get) 156 | 157 | # set sequencer setters 158 | for key, c in self._S_funcdict.items(): 159 | funcs = self._get_S_callbacks(c) 160 | setattr(self, "set_S_" + key, funcs[0]) 161 | setattr(self, "get_S_" + key, funcs[1]) 162 | 163 | S_note_set, S_note_get = self._get_S_note_callback() 164 | setattr(self, "set_S_note", S_note_set) 165 | setattr(self, "get_S_note", S_note_get) 166 | 167 | setattr(self, "set_S_on", self._get_S_toggle_callback(127)) 168 | setattr(self, "set_S_off", self._get_S_toggle_callback(0)) 169 | setattr(self, "get_S_onoff", self._get_S_toggle_get_callback()) 170 | 171 | def recall_preset(self, slot): 172 | return (240, 0, 32, 107, 127, 66, 5, slot, 247) 173 | 174 | def store_preset(self, slot): 175 | return (240, 0, 32, 107, 127, 66, 6, slot, 247) 176 | 177 | def set_global_channel(self, val): 178 | return self._send_change(64, 6, val) 179 | 180 | def get_global_channel(self): 181 | return self._send_request(64, 6) 182 | 183 | def _send_change(self, c, ID, val): 184 | return self._B_START_MSG + (c, ID, val, 247) 185 | 186 | def _send_request(self, c, ID): 187 | return self._B_REQUEST_MSG + (c, ID, 247) 188 | 189 | def _get_callbacks(self, c): 190 | # do this to ensure function-name closure! 191 | def changeB(ID, val): 192 | return self._send_change(c, self._B[ID], val) 193 | 194 | def requestB(ID): 195 | return self._send_request(c, self._B[ID]) 196 | 197 | def changeE(ID, val): 198 | return self._send_change(c, self._E[ID], val) 199 | 200 | def requestE(ID): 201 | return self._send_request(c, self._E[ID]) 202 | 203 | return changeB, requestB, changeE, requestE 204 | 205 | def _get_velocity_callback(self): 206 | def set_callback(val): 207 | return self._send_change(65, 3, val) 208 | 209 | def get_callback(): 210 | return self._send_request(65, 3) 211 | 212 | return set_callback, get_callback 213 | 214 | def _get_acceleration_callback(self): 215 | def set_callback(val): 216 | return self._send_change(65, 4, val) 217 | 218 | def get_callback(): 219 | return self._send_request(65, 4) 220 | 221 | return set_callback, get_callback 222 | 223 | def _get_S_callbacks(self, c): 224 | def set_callback(val): 225 | return self._send_change(80, c, val) 226 | 227 | def get_callback(): 228 | return self._send_request(80, c) 229 | 230 | return set_callback, get_callback 231 | 232 | def _get_S_note_callback(self): 233 | def set_callback(ID, val): 234 | return self._send_change(82, ID, val) 235 | 236 | def get_callback(ID): 237 | return self._send_request(82, ID) 238 | 239 | return set_callback, get_callback 240 | 241 | def _get_S_toggle_callback(self, val): 242 | def set_callback(ID): 243 | return self._send_change(83, ID, val) 244 | 245 | return set_callback 246 | 247 | def _get_S_toggle_get_callback(self): 248 | def get_callback(ID): 249 | return self._send_request(83, ID) 250 | 251 | return get_callback 252 | 253 | def decode(self, b): 254 | whatQ, control, val = None, None, None 255 | 256 | if not b[:8] == self._B_START_MSG: 257 | pass 258 | else: 259 | Q, ID, value = b[8:11] 260 | 261 | for key, val in self._B.items(): 262 | if val == ID: 263 | control = "button_" + str(key) 264 | break 265 | else: 266 | continue 267 | if control is None: 268 | for key, val in self._E.items(): 269 | if val == ID: 270 | control = "encoder_" + str(key) 271 | break 272 | else: 273 | continue 274 | 275 | for key, val in self._funcdict.items(): 276 | if val == Q: 277 | whatQ = key 278 | 279 | return whatQ, control, value 280 | -------------------------------------------------------------------------------- /BeatStep_Q.py: -------------------------------------------------------------------------------- 1 | # Embedded file name: /Users/versonator/Jenkins/live/output/Live/mac_64_static/Release/python-bundle/MIDI Remote Scripts/BeatStep/BeatStep_Q.py 2 | from __future__ import absolute_import, print_function, unicode_literals 3 | import Live 4 | 5 | # from _Arturia.ArturiaControlSurface import ArturiaControlSurface 6 | from _Framework.ControlSurface import ControlSurface 7 | from _Framework.Layer import Layer 8 | from _Framework.InputControlElement import MIDI_CC_TYPE, MIDI_NOTE_TYPE 9 | from _Framework.ButtonElement import ButtonElement 10 | from _Framework.EncoderElement import EncoderElement 11 | from _Framework import Task 12 | from _Framework.ButtonMatrixElement import ButtonMatrixElement 13 | from _Framework.DeviceComponent import DeviceComponent 14 | 15 | from .QControlComponent import QControlComponent 16 | from .QSetup import QSetup 17 | 18 | ENCODER_MSG_IDS = (10, 74, 71, 76, 77, 93, 73, 75, 114, 18, 19, 16, 17, 91, 79, 72) 19 | PAD_MSG_IDS = list(range(44, 52)) + list(range(36, 44)) 20 | 21 | # the midi-channel to use for buttons and encoders 22 | CHANNEL = 9 23 | # the used memory-slot to store the configurations 24 | MEMORY_SLOT = 8 25 | 26 | SETUP_HARDWARE_DELAY = 2.1 27 | 28 | 29 | class BeatStep_Q(ControlSurface): 30 | def __init__(self, *a, **k): 31 | super(BeatStep_Q, self).__init__(*a, **k) 32 | 33 | self.QS = QSetup() 34 | self.control_layer_active = False 35 | 36 | with self.component_guard(): 37 | self._setup_hardware_task = self._tasks.add( 38 | Task.sequence( 39 | Task.wait(SETUP_HARDWARE_DELAY), Task.run(self._setup_hardware) 40 | ) 41 | ) 42 | self._setup_hardware_task.kill() 43 | self._start_hardware_setup() 44 | 45 | self._create_controls() 46 | self._create_Q_control() 47 | 48 | self._create_device() 49 | 50 | def receive_midi(self, midi_bytes): 51 | # self.show_message(str(midi_bytes)) 52 | super(BeatStep_Q, self).receive_midi(midi_bytes) 53 | 54 | def handle_sysex(self, midi_bytes): 55 | # self.show_message(str(midi_bytes)) 56 | super(BeatStep_Q, self).handle_sysex(midi_bytes) 57 | 58 | def port_settings_changed(self): 59 | super(BeatStep_Q, self).port_settings_changed() 60 | self._start_hardware_setup() 61 | 62 | def _start_hardware_setup(self): 63 | # kill already running setup tasks: 64 | self._setup_hardware_task.kill() 65 | self._messages_to_send = [] 66 | self._setup_hardware_task.restart() 67 | 68 | def _B_color_callback(self, b, c): 69 | # do this to ensure callback-name closure 70 | def f(): 71 | self._send_midi(self.QS.set_B_color(b, c)) 72 | 73 | return f 74 | 75 | def _init_color_sequence(self): 76 | for i in range(1, 9): 77 | self.schedule_message(i, self._B_color_callback(i, 1)) 78 | self.schedule_message(17 - i, self._B_color_callback(i, 16)) 79 | for i in range(1, 17): 80 | self.schedule_message(20, self._B_color_callback(i, 0)) 81 | 82 | def _setup_hardware(self): 83 | self._init_color_sequence() 84 | self._setup_control_buttons_and_encoders() 85 | self._setup_buttons_and_encoders() 86 | 87 | # set pad velocity to 0 (e.g. linear) on startup 88 | self._send_midi(self.QS.set_B_velocity(0)) 89 | # set encoder acceleration to "slow" on startup 90 | self._send_midi(self.QS.set_E_acceleration(0)) 91 | 92 | def _setup_control_buttons_and_encoders(self): 93 | """ 94 | this function is only called once when the BeatStep is plugged in to 95 | ensure correct assignments of function-buttons and transpose encoder 96 | """ 97 | # set shift button to note-mode 98 | self._send_midi(self.QS.set_B_mode("shift", 8)) 99 | self._send_midi(self.QS.set_B_channel("shift", CHANNEL)) 100 | self._send_midi(self.QS.set_B_behaviour("shift", 1)) 101 | 102 | # set stop button to note-mode 103 | self._send_midi(self.QS.set_B_mode("stop", 8)) 104 | self._send_midi(self.QS.set_B_channel("stop", CHANNEL)) 105 | self._send_midi(self.QS.set_B_behaviour("stop", 1)) 106 | 107 | # set play button to note-mode 108 | self._send_midi(self.QS.set_B_mode("play", 8)) 109 | self._send_midi(self.QS.set_B_channel("play", CHANNEL)) 110 | self._send_midi(self.QS.set_B_behaviour("play", 1)) 111 | 112 | # set cntrl/seq button to note-mode 113 | self._send_midi(self.QS.set_B_mode("cntrl", 8)) 114 | self._send_midi(self.QS.set_B_channel("cntrl", CHANNEL)) 115 | # set button behaviour to toggle 116 | self._send_midi(self.QS.set_B_behaviour("cntrl", 0)) 117 | 118 | # set chan button to note mode 119 | self._send_midi(self.QS.set_B_mode("chan", 8)) 120 | self._send_midi(self.QS.set_B_channel("chan", CHANNEL)) 121 | self._send_midi(self.QS.set_B_behaviour("chan", 1)) 122 | 123 | # set store button to note mode 124 | self._send_midi(self.QS.set_B_mode("store", 8)) 125 | self._send_midi(self.QS.set_B_channel("store", CHANNEL)) 126 | self._send_midi(self.QS.set_B_behaviour("store", 1)) 127 | 128 | # set store button to note mode 129 | self._send_midi(self.QS.set_B_mode("recall", 8)) 130 | self._send_midi(self.QS.set_B_channel("recall", CHANNEL)) 131 | self._send_midi(self.QS.set_B_behaviour("recall", 1)) 132 | 133 | # set transpose encoder channel 134 | self._send_midi(self.QS.set_E_channel("transpose", CHANNEL)) 135 | self._send_midi(self.QS.set_E_behaviour("transpose", 2)) 136 | # set encoder cc to something else than the shift-encoder cc 137 | # (4 is unused since it would represent the ext/sync button) 138 | self._send_midi(self.QS.set_E_cc("transpose", 4)) 139 | 140 | def _setup_buttons_and_encoders(self): 141 | # for all buttons and encoders 142 | for i in range(1, 17): 143 | # set pad to note-mode 144 | self._send_midi(self.QS.set_B_mode(i, 9)) 145 | # set pad channel 146 | self._send_midi(self.QS.set_B_channel(i, CHANNEL)) 147 | # set pad behaviour to toggle 148 | self._send_midi(self.QS.set_B_behaviour(i, 1)) 149 | 150 | # set encoder channel 151 | self._send_midi(self.QS.set_E_channel(i, CHANNEL)) 152 | # set all encoders to relative-mode 2 153 | self._send_midi(self.QS.set_E_behaviour(i, 2)) 154 | # set all encoders to midi cc mode 155 | self._send_midi(self.QS.set_E_mode(i, 1)) 156 | # set midi cc id's for all encoders 157 | self._send_midi(self.QS.set_E_cc(i, ENCODER_MSG_IDS[i - 1])) 158 | 159 | def _do_activate_control_mode(self): 160 | # for all buttons 161 | for i in range(1, 17): 162 | # set pad to cc-mode 163 | self._send_midi(self.QS.set_B_mode(i, 8)) 164 | # set pad channel 165 | self._send_midi(self.QS.set_B_channel(i, CHANNEL)) 166 | # set pad behaviour to toggle 167 | self._send_midi(self.QS.set_B_behaviour(i, 1)) 168 | 169 | # set encoder channel 170 | self._send_midi(self.QS.set_E_channel(i, CHANNEL)) 171 | # set all encoders to relative-mode 2 172 | self._send_midi(self.QS.set_E_behaviour(i, 2)) 173 | 174 | # set transpose encoder channel to follow global channel 175 | self._send_midi(self.QS.set_E_channel("transpose", CHANNEL)) 176 | # set transpose encoder to relative mode 2 177 | self._send_midi(self.QS.set_E_behaviour("transpose", 2)) 178 | 179 | def _deactivate_control_mode(self): 180 | self._send_midi(self.QS.recall_preset(MEMORY_SLOT)) 181 | # make sure that buttons relevant for control-features 182 | # are correctly set 183 | # self._setup_control_buttons_and_encoders() 184 | 185 | # set pad velocity 186 | self._send_midi(self.QS.set_B_velocity(self._control_component._pad_velocity)) 187 | 188 | self.control_layer_active = False 189 | 190 | def _activate_control_mode(self): 191 | # only save the current configuration if no control-layer is active 192 | if not self.control_layer_active: 193 | self._send_midi(self.QS.store_preset(MEMORY_SLOT)) 194 | 195 | self._do_activate_control_mode() 196 | self.control_layer_active = True 197 | 198 | def _create_controls(self): 199 | self._play_button = ButtonElement( 200 | True, MIDI_CC_TYPE, CHANNEL, 2, name="Play_Button" 201 | ) 202 | self._play_S_button = ButtonElement( 203 | True, MIDI_NOTE_TYPE, 0, 60, name="Play_Button" 204 | ) 205 | 206 | self._stop_button = ButtonElement( 207 | True, MIDI_CC_TYPE, CHANNEL, 1, name="Stop_Button" 208 | ) 209 | self._cntrl_button = ButtonElement( 210 | True, MIDI_CC_TYPE, CHANNEL, 3, name="cntrl_Button" 211 | ) 212 | self._recall_button = ButtonElement( 213 | True, MIDI_CC_TYPE, CHANNEL, 5, name="recall_Button" 214 | ) 215 | self._store_button = ButtonElement( 216 | True, MIDI_CC_TYPE, CHANNEL, 6, name="store_Button" 217 | ) 218 | self._shift_button = ButtonElement( 219 | True, MIDI_CC_TYPE, CHANNEL, 7, name="Shift_Button" 220 | ) 221 | self._chan_button = ButtonElement( 222 | True, MIDI_CC_TYPE, CHANNEL, 8, name="chan_Button" 223 | ) 224 | 225 | for i in range(1, 17): 226 | bmsgid = PAD_MSG_IDS[i - 1] 227 | setattr( 228 | self, 229 | "_" + str(i) + "_button", 230 | ButtonElement( 231 | True, MIDI_CC_TYPE, CHANNEL, bmsgid, name="_" + str(i) + "_button" 232 | ), 233 | ) 234 | 235 | emsgid = ENCODER_MSG_IDS[i - 1] 236 | setattr( 237 | self, 238 | "_" + str(i) + "_encoder", 239 | EncoderElement( 240 | MIDI_CC_TYPE, 241 | CHANNEL, 242 | emsgid, 243 | Live.MidiMap.MapMode.relative_smooth_two_compliment, 244 | name="_" + str(i) + "_encoder", 245 | ), 246 | ) 247 | 248 | self._transpose_encoder = EncoderElement( 249 | MIDI_CC_TYPE, 250 | CHANNEL, 251 | 4, 252 | Live.MidiMap.MapMode.relative_smooth_two_compliment, 253 | name="_transpose_encoder", 254 | ) 255 | 256 | self._device_encoders = ButtonMatrixElement( 257 | rows=[ 258 | [ 259 | EncoderElement( 260 | MIDI_CC_TYPE, 261 | CHANNEL, 262 | identifier, 263 | Live.MidiMap.MapMode.relative_smooth_two_compliment, 264 | name="Encoder_%d_%d" % (column_index, row_index), 265 | ) 266 | for column_index, identifier in enumerate(row) 267 | ] 268 | for row_index, row in enumerate( 269 | (ENCODER_MSG_IDS[:4], ENCODER_MSG_IDS[8:12]) 270 | ) 271 | ] 272 | ) 273 | 274 | def _create_Q_control(self): 275 | 276 | self._control_component = QControlComponent(self) 277 | self._control_component.set_shift_button(self._shift_button) 278 | self._control_component.set_stop_button(self._stop_button) 279 | self._control_component.set_play_button(self._play_button) 280 | self._control_component.set_play_S_button(self._play_S_button) 281 | self._control_component.set_cntrl_button(self._cntrl_button) 282 | self._control_component.set_chan_button(self._chan_button) 283 | self._control_component.set_store_button(self._store_button) 284 | self._control_component.set_recall_button(self._recall_button) 285 | 286 | self._control_component.set_transpose_encoder_button(self._transpose_encoder) 287 | 288 | for i in range(1, 17): 289 | getattr(self._control_component, "set_" + str(i) + "_button")( 290 | getattr(self, "_" + str(i) + "_button") 291 | ) 292 | 293 | for i in range(1, 17): 294 | getattr(self._control_component, "set_" + str(i) + "_encoder_button")( 295 | getattr(self, "_" + str(i) + "_encoder") 296 | ) 297 | 298 | def _create_device(self): 299 | self._device = DeviceComponent( 300 | name="Device", 301 | is_enabled=False, 302 | layer=Layer(parameter_controls=self._device_encoders), 303 | device_selection_follows_track_selection=True, 304 | ) 305 | self._device.set_enabled(True) 306 | self.set_device_component(self._device) 307 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Beatstep_Q 2 | **Beatstep_Q** is a **MIDI Remote Script** for **Ableton Live 9, 10 & 11** and the **Arturia BeatStep** controller. 3 | It turns your BeatStep into a fully-fledged control-surface for Ableton Live ! 4 | 5 | - there are 6 different layers that give you a lot of control over Ableton Live: 6 | - play midi instruments with access to the **full range** of midi-notes! 7 | - browse Ableton's library (in the info-bar) and prelisten/load/hotswap instruments & devices 8 | - control tracks/scenes and clips 9 | - select / arm / mute / solo / start / stop / record / delete / duplicate / overdub / undo / redo / ... 10 | - initialize and edit 16 note MIDI-sequences 11 | - change properties of one or more notes simultaneously via the "multi-touch" editing mode 12 | - get indications on the status of clips, tracks, playback-state and MIDI notes via button-LED's 13 | - ... and much more! 14 | 15 | ### Comments / suggestions / bugs? 16 | > Just drop an [Issue](https://github.com/raphaelquast/beatstep/issues) or start a [Discussion](https://github.com/raphaelquast/beatstep/discussions) and I'll see what I can do! 17 | 18 | 19 | ... and as you might imagine... 20 | developing and maintaining all of this is quite some work, so if you like what I did, how about buying me a coffee? 21 | 22 |
23 | Buy Me A Coffee 24 |
25 | 26 | # Installation 27 | 28 | No real installation required... just copy the files, and you are ready to go! 29 | 30 | 1) copy all files of the latest [release](https://github.com/raphaelquast/beatstep/releases) into a folder named **"Beatstep_Q"** 31 | inside the MIDI Remote scripts folder of Ableton Live 32 | (located at `..install-dir..\Resources\MIDI Remote Scripts`) 33 | 2) start Ableton and select **Beatstep_Q** as control-surface in the MIDI-tab of the preferences. 34 | (make sure to activate both `track` and `remote` for this device!) 35 | 36 | ❗BeatStep's **storage bank 9** is used during runtime. Any configuration stored to this slot will be overwritten❗ 37 | 38 | # Overlay 39 | The overlay-design provides indications for all assignments (including secondary-functions) 40 | 41 | (I got mine printed here: [Taktility](https://www.taktility.com/)) 42 | 43 | 44 | 45 | 48 | 51 | 52 |
46 | 47 | 49 | 50 |
53 | 54 | 55 | # Summary of Assignments 56 | 57 | ![assignments-image](/assignment_01.png) 58 | 59 | --- 60 | 61 | # More detailed explanations on the assignments: 62 | 63 | The script will set all encoders and buttons to send messages on the Midi-channel 10. To indicate a successful setup, the top-row will light up red and blue (about 2 seconds after plugin). 64 | 65 | - It's best to **connect the controller after Ableton started** to ensure that all settings are properly assigned. 66 | 67 | - To ensure that the script is automatically selected (instead of the default script), rename the already existing *"Beatstep"* folder to *"_Beatstep"* (or something that it is alphabetically sorted **after** *"BeatStep_Q"*) 68 | 69 | > After initialization, you can recall any saved MIDI configuration and the control-layers will still work! 70 | 71 | 72 | 73 | 74 | 75 | 76 | ## General (click to expand) 77 | 78 |
:black_square_button: BUTTONS 79 | 80 | The buttons `recall`, `store`,`chan` and `shift` are used to activate the control-layers. 81 | 82 | - to maintain the initial functionality of the buttons, the layers are activated when the buttons are **released** ! 83 | 84 | - all layers (except the *"shift-layer"*) remain activated until the corresponding button is pressed again 85 | 86 | - holding `shift` and pressing `chan` will activate the *"mix-layer"* 87 | - holding `shift` and pressing `recall` will activate the *"browser-layer"* 88 | 89 | - **double-tapping** `shift` will activate the *"shift-layer"* permanently (until shift is pressed again) 90 | 91 | - the *"if shift pressed"* features are only available if the corresponding layer is activated permanently **and** `shift` is pressed 92 | 93 | The `stop` button works the same (on all layers) as follows: 94 | 95 | - if the selected clip is currently recording: only recording is stopped (but playback is continued) 96 | 97 | - if the selected clip is playing: stop is triggered 98 | 99 | - *"if shift pressed"* : stop **ALL** tracks 100 | 101 | > While no layer is active, all buttons can be used to play midi-notes! 102 | > (>> use the `transpose-encoder` to change the assigned range of midi-notes) 103 | 104 | 105 |
106 | 107 | 108 | --- 109 | 110 |
:white_circle: ENCODERS 111 | 112 | The `transpose-encoder` can be used to transpose the note-assignments of the buttons. 113 | (a red button-color indicates that the lower-left button is at the note C-2, C-1, C0, C1, etc.) 114 | > The info-message also tells you the current assignment of the lower-left button (e.g. `button 9`) 115 | 116 | - `encoder 1-4` and `9-12` : control the first 8 parameters of the selected device 117 | 118 | - `encoder 5, 6, 13, 14` : send A, B, C, D of selected track 119 | 120 | - `encoder 7` : volume of selected track 121 | 122 | - *"if shift pressed"*: volume of master-track 123 | 124 | - `encoder 15` : pan of selected track 125 | 126 | - *"if shift pressed"*: pan of master-track 127 | 128 | - `encoder 8` : track-selection (left-right) [💡 this is the same for all layers!] 129 | 130 | - *"if shift pressed"* **and** a *"drum-rack"* is selected: 131 | 132 | select drum-pad slot of the viewed 16 slots 133 | 134 | - `encoder 16` : scene selection (up-down) [💡 this is the same for all layers!] 135 | - *"if shift pressed"* **and** a *"drum-rack"* is selected: 136 | 137 | select row of viewed drum-pads 138 | 139 |
140 | 141 | --- 142 | 143 | ## Layers (click to expand) 144 | 145 | 146 |
147 | :trumpet: SHIFT 148 | 149 | If NO other layer is activated, pressing "shift" temporarily activates the `shift` layer 150 | It serves as a *quick-access* layer for frequently used functions. 151 | The layer is deactivated as soon as `shift` is released! 152 | **double-tap** `shift` to activate the layer permanently. 153 | 154 | 155 | The lights in the first indicate the currently activated clip. 156 | (`red` for midi, `blue` for audio and `magenta` for return tracks) 157 | 158 | The lights in the second row indicate the track-arm status: 159 | 160 | - `red` if the track is **armed** and **not muted** 161 | 162 | - `magenta` if the track is armed but muted 163 | 164 | - `blue` if the track represents a **track-group** 165 | 166 | - `off` if the track is muted and **not** armed 167 | 168 | 169 | #### The assignments are as follows: 170 | 171 | - `button 1-7`: select track 1-7 of the currently focussed slots (red box) 172 | 173 | - double tap an already selected track to arm/unarm it 174 | - if the selected track is a track-group, instead fold/unfold the group 175 | 176 | - `button 8`: select previous scene (e.g. go 1 scene up) 177 | 178 | - if the control-layer is activated permanently, holding `shift` will switch to track-selection 179 | 180 | - `button 9` : undo last step 181 | 182 | - `button 10`: delete selected clip 183 | 184 | - `button 12`: duplicate the currently selected clip and set the focus to the duplicate 185 | 186 | - `button 13`: duplicate the currently selected loop 187 | 188 | - `button 15`: start recording 189 | 190 | - if the currently selected slot is empty, start recording a new clip 191 | 192 | - if a clip is already present, toggle overdubbing the clip 193 | 194 | - `button 16` : select next scene (if at the end, create a new scene) 195 | 196 | - if the control-layer is activated permanently, holding `shift` will switch to track-selection 197 | 198 | All encoders are assigned as described above except for the `transpose-encoder`, which is now used to **select devices** in the device-chain of the selected track. (turning the `transpose-encoder` will automatically focus the view to the device-chain!) 199 | 200 |
201 | 202 | --- 203 | 204 |
205 | :open_file_folder: BROWSE 206 | The browser works ONLY in the info-bar... it is not connected to Ableton's browser-window! 207 | (I know this would be nice... but the Ableton python-API does not allow it) 208 | The status-bar symbols indicate the following: 209 | 210 | - :red_circle: : the selected item can be loaded 211 | - :fire: ... :fire: : hotswap is active 212 | - :arrows_counterclockwise: : the item can be hotswapped 213 | - :black_circle: : the item can not be loaded directly (it's a collection of sub-items) 214 | - :file_folder: : the item is a folder (and can not be loaded directly) 215 | - :small_blue_diamond: a loadable item that is not selected 216 | 217 | Most button-lights are simply there to help remember the button-assignments. 218 | - `button 13` indicates if **hotswap** is on or off (`red` for on) 219 | - `button 14` indicates if **prelisten** is on or off (`blue` for on) 220 | 221 | #### The assignments are as follows: 222 | 223 | - `button 1` : open **sounds** 224 | - `button 2` : open **drums** 225 | - `button 3` : open **instruments** 226 | - `button 4` : open **audio-effects** 227 | - `button 5` : open **MIDI-effects** 228 | - `button 6` : open **samples** 229 | - `button 7` : open **collections** 230 | - `button 8` : select previous track 231 | - "if shift pressed" : select previous device 232 | 233 | - `button 9` : go 1 item left 234 | - `button 10` : go 1 item right 235 | - `button 11` : go 1 folder-level down (if possible) 236 | - `button 12` : go 1 folder-level up (if possible) 237 | - `button 13` : toggle hotswapping the currently selected instrument/device 238 | - `button 14` : toggle item-preview 239 | - `button 15` : load the selected item (on the currently selected track if possible) 240 | - "if shift pressed" : load the selected item on a new track 241 | - `button 16` : select next track 242 | - "if shift pressed" : select next device 243 | 244 | 245 | All encoders are assigned similar to the *"shift-layer"*. 246 | 247 | 248 |
249 | 250 | --- 251 | 252 |
253 | :violin: CONTROL 254 | 255 | Most lights are simply there to help remember the button-assignments. 256 | The lights of `button 13` and `button 14` indicate the status of their corresponding parameter in Live. 257 | 258 | - `button 13` indicates the status of the metronome (`red` for on) 259 | - `button 14` indicates the status of "automation arm" (`red` for active) 260 | - "if shift pressed" and an automation has been overridden, the button will turn `blue` 261 | 262 | - `button 3`, `10` and `11` will turn red if shift is pressed to highlight the alternative functionality 263 | 264 | #### The assignments are as follows: 265 | 266 | - `button 1` : redo last step 267 | 268 | - `button 2` : fold / unfold selected device 269 | 270 | - `button 3` : activate / deactivate selected device 271 | 272 | - *"if shift pressed"* : delete selected device 273 | 274 | - `button 6` : cycle through the *"launch-quantization"* times (e.g. 1 bar, 1/2 bar, 1/8 bar etc.) 275 | 276 | - *"if shift pressed"* : turn *"launch-quantization"* off 277 | 278 | - `button 7` : toggle between showing the selected *"clip-details"* or the *"device-chain"* of the selected track 279 | 280 | - *"if shift pressed"* : toggle between Ableton's session-view and arrangement-view 281 | 282 | - `button 8` : select previous scene (e.g. go 1 scene up) 283 | 284 | - - *"if shift pressed"* : select previous track 285 | 286 | - `button 9` : undo last step 287 | 288 | - `button 10` : duplicate selected track 289 | 290 | - "if shift pressed" : delete selected track 291 | 292 | - `button 11` : duplicate selected scene 293 | 294 | - *"if shift pressed"* : delete selected scene 295 | 296 | - `button 12` : tap tempo 297 | 298 | - `button 13` : toggle metronome 299 | 300 | - `button 14` : toggle *"session automation record"* 301 | 302 | - *"if shift-pressed"* and an automation has been overridden: *"re-enable automation"* 303 | 304 | - `button 15` : change the assigned "pad velocity curve" (e.g. the midi velocity response of the pad) 305 | 306 | - `blue` for linear, `magenta` for logarithmic, `red` for exponential and `off` for "always max. velocity" 307 | 308 | - `button 16` : select next scene (if at the end, create a new scene) 309 | 310 | - *"if shift-pressed"*: select next track 311 | 312 | All encoders are assigned similar to the *"shift-layer"*. 313 | 314 |
315 | 316 | --- 317 | 318 |
319 | :guitar: LAUNCH 320 | 321 | In this control-layer, both button-rows (e.g. `1-7` and `9-15`) represent clip-slots. 322 | NOTICE: the `stop` button has a special feature in this layer (see below). 323 | 324 | There are 2 possible ways to activate this layer: 325 | 326 | - tap `store` to control **2 clip-slots of 7 tracks** 327 | - only the `store` button LED will be on 328 | - tap `shift + store` to control **14 clip-slots of 1 track** 329 | - the LED's of `store`, `chan` and `recall` will be on 330 | 331 | The button-lights indicate the status of the clip-slots, e.g.: 332 | 333 | - `blue` indicates a slot with a clip 334 | - a `blue blinking` slot indicates a clip that is triggered to **stop** 335 | 336 | - `red` indicates a clip that is playing 337 | - a `red blinking` slot indicates a clip that is triggered to **play** 338 | 339 | - `magenta` indicates a group-track (it will turn `red` if a clip of the group is playing) [or indicate a triggered clip in `shift + store` mode] 340 | 341 | - the `shift` button indicates if *"re-trigger clips"* or *"stop clips"* mode is active 342 | 343 | #### The assignments are as follows: 344 | 345 | - the `stop-button` toggles the behavior of the buttons (indicated by the `shift` button LED) 346 | 347 | - *"re-trigger clips"* mode (`shift` LED OFF) : tapping on an already playing clip will **re-trigger** the clip 348 | 349 | - *"stop clips"* mode (`shift` LED ON) : tapping on an already playing clip will **stop** the clip 350 | 351 | (... the *"if shift-pressed"* behavior is still similar to the other layers, e.g. *"stop all clips"*) 352 | 353 | - `button 1-7` : launch the clips present in the top-row of the selection. 354 | 355 | - *"if shift-pressed"* : select the track to which the clip-slot belongs to 356 | - if the slot is a "group-slot": fold/unfold the corresponding group 357 | 358 | - `button 8` : select previous scene (e.g. go 1 scene up) 359 | 360 | - *"if shift-pressed"*: select previous track 361 | 362 | - `button 9-15` : same as `1-7` but for the bottom row of the selection. 363 | 364 | - `button 16` : select next scene (if at the end, add a new scene) 365 | 366 | - *"if shift-pressed"*: select next track 367 | 368 | All encoders are assigned similar to the *"shift-layer"*. 369 | 370 |
371 | 372 | --- 373 | 374 |
375 | :headphones: MIX 376 | 377 | The lights in the top-row indicate the mute / solo status of the corresponding track. 378 | 379 | - `blue` for a track that is set to solo 380 | 381 | - `magenta` for an unmuted track 382 | 383 | - `red` if the track is both solo and muted 384 | 385 | - `off` if the track is muted and not solo 386 | 387 | The lights in the bottom-row indicate the arm status of the corresponding track. 388 | 389 | - `red` if the track is armed 390 | 391 | - `blue` if the track represents a track-group 392 | 393 | - `off` if the track is unarmed (and no track-group) 394 | 395 | #### The assignments are as follows: 396 | 397 | - `button 1-7` : set the **mute** status of the first 6 tracks in the red box 398 | 399 | - *"if shift pressed"*: **solo** the corresponding track 400 | 401 | - `button 9-15` : set the **arm** status of the first 7 tracks in the red box 402 | 403 | - if the track represents a group, fold / unfold the corresponding group 404 | 405 | - `button 8` : select previous scene (e.g. go 1 scene up) 406 | 407 | - *"if shift pressed"*: select previous track 408 | 409 | - `button 16` : select next scene (if at the end, create a new scene) 410 | 411 | - "if shift pressed" : select next track 412 | 413 | - `encoder 1-7` : *"track volume"* of corresponding track 414 | 415 | - *"if shift pressed"* : *"send A"* of corresponding track 416 | 417 | - `encoder 9-15` : *"track pan"* of corresponding track 418 | 419 | - *"if shift pressed"* : *"send B"* of corresponding track 420 | 421 | - `encoder 8` : track-selection (left-right) 422 | 423 | - `encoder 16` : scene selection (up-down) 424 | 425 | - `transpose encoder` : set volume of master-track 426 | 427 |
428 | 429 | --- 430 | 431 |
432 | :musical_score: SEQUENCER 433 | 434 | The `sequencer`-layer is only available in **Ableton 11** or newer! 435 | 436 | The `sequencer` layer has 2 different functionalities: 437 | 438 | - If `shift` is pressed, you can use all button-functions from the `shift`-layer! 439 | 440 | 441 | NOTE: The first 6 characters of a clip-name are used to parse the tempo of the midi sequence! 442 | > E.g. a clip-name starting with `1/32_Q` will be identified as having a tempo of 1/32. 443 | > Any characters after the first 6 are ignored. (e.g. a name of `1/32_Q what a nice clip` is fine!) 444 | 445 | 446 |
447 | :ant: SEQUENCE EDITOR (active if a MIDI clip is selected) 448 | 449 | In the sequence-editor mode you can edit the first 16 notes of the selected MIDI clip. 450 | 451 | - the colors of `buttons 1-16` are 452 | - `black` if there is no note or the note is muted 453 | - `blue` if there is a note, and it is unmuted 454 | - `magenta` if the note is unmuted and outside the loop 455 | - it also indicates if less than 16 notes are present 456 | - a moving `red` light indicates the playback-state of the clip 457 | 458 | - check the Ableton info-bar for info-messages! 459 | 460 | #### The assignments are as follows: 461 | 462 | - multi-touch editing mode: 463 | - touch & hold one (or more) buttons and turn the `transpose`-encoder to change the assigned property of the selected notes 464 | - use `encoder 1-6` to set which property you want to change 465 | 466 | - `button 1-16` : mute/unmute corresponding note 467 | - `shift` + `button 1-16` : use functionality of `shift`-layer 468 | 469 | - `encoder 1` : set encoders to change **note pitch** 470 | - `encoder 2` : set encoders to change **note velocity** 471 | - `encoder 3` : set encoders to change **note start-time** 472 | - `encoder 4` : set encoders to change **note duration** 473 | - `encoder 5` : set encoders to change **note velocity-deviation** 474 | - `encoder 6` : set encoders to change **note probability** 475 | 476 | - `encoder 8` : select prev/next track 477 | 478 | - `encoder 9` : change the loop start-time (coarse steps) 479 | - `encoder 10` : change the loop start-time (fine steps) 480 | - `encoder 11` : change the position of the loop (fine steps) 481 | - `encoder 12` : change the loop end-time (fine steps) 482 | - `encoder 13` : change the loop end-time (coarse steps) 483 | 484 | - `encoder 15` : transpose all notes that are inside the loop 485 | - `encoder 16` : select prev/next scene 486 | 487 | - `shift` + `encoder 1-16` : change assigned parameter of corresponding note 488 | 489 |
490 | 491 | 492 |
493 | :hatching_chick: SEQUENCE INITIALIZER (active if the selected clip-slot is empty) 494 | 495 | In the sequence-initializer layer you can set the start-parameters for the midi-sequence 496 | that is initialized if you press `chan` again. 497 | 498 | - `buttons` 1-8 indicates the tempo of the MIDI notes as "notes/bar" 499 | [1/32, 1/16, 1/8, 1/4, 1/2, 1, 2, 4] 500 | 501 | - `buttons` 9, 10, 11, 12 indicate how the note-interval is filled 502 | - NOTE you can also use this to offset the notes! 503 | - `buttons`13, 14, 15, 16 indicate the velocity of the notes (0.25, 0.5, 0.75, 1) 504 | 505 | - check the Ableton info-bar for info-messages! 506 | 507 | #### The assignments are as follows: 508 | 509 | - `buttons` 1-8: set sequence-tempo 510 | - `buttons` 9, 10, 11, 12 : set note-interval 511 | - `buttons`13, 14, 15, 16 : set velocity 512 | - **double-tap** `shift` : initialize a 16 note midi sequence with the selected parameters 513 | 514 | - `transpose-encoder` : set the note-pitch for the initialized sequence 515 | 516 | - `encoder 1` : set encoders to change **note pitch** 517 | - `encoder 2` : set encoders to change **note velocity** 518 | - `encoder 3` : set encoders to change **note start-time** 519 | - `encoder 4` : set encoders to change **note duration** 520 | - `encoder 5` : set encoders to change **note velocity-deviation** 521 | - `encoder 6` : set encoders to change **note probability** 522 | 523 | - `encoder 8` : select prev/next track 524 | 525 | - `encoder 9` : set pitch increment of notes 526 | - `encoder 10` : set number of incremented notes 527 | 528 | - `encoder 15` : transpose all notes that are inside the loop 529 | - `encoder 16` : select prev/next scene 530 | 531 |
532 | 533 | 534 |
535 | --- 536 | 537 | ## Thanks to 538 | 539 | - [untergeek](https://www.untergeek.de/2014/11/taming-arturias-beatstep-sysex-codes-for-programming-via-ipad/) for unravelling BeatStep sysex messages 540 | 541 | - Julien Bayle for the awesome [PythonLiveAPI_documentation](https://julienbayle.studio/PythonLiveAPI_documentation/) and some more info's ( [here](https://julienbayle.studio/ableton-live-midi-remote-scripts/) ) 542 | 543 | - Hanz Petrov for his [Introduction to the Framework-classes](https://livecontrol.q3f.org/ableton-liveapi/articles/introduction-to-the-framework-classes/) and the corresponding [remotescripts-blog](http://remotescripts.blogspot.com) 544 | 545 | --- 546 | 547 | -------------------------------------------------------------------------------- /QBrowser.py: -------------------------------------------------------------------------------- 1 | import Live 2 | from .QSetup import QSetup 3 | 4 | NavDirection = Live.Application.Application.View.NavDirection 5 | FilterType = Live.Browser.FilterType 6 | DeviceType = Live.Device.DeviceType 7 | Relation = Live.Browser.Relation 8 | 9 | # fmt: off 10 | 11 | symb_folder = u"\U0001f4c1" 12 | symb_folder_open = u"\U0001f4c2" 13 | symb_red_circle = u"\U0001f534" 14 | symb_orange_circle = u"\U0001f7e0" 15 | symb_red_box = u"\U0001f7e5" 16 | symb_circle_arrow = u"\U0001f504" 17 | 18 | symb_blue_diamond_large = u"\U0001F537" 19 | symb_blue_diamond_small = u"\U0001f539" 20 | symb_fire = u"\U0001f525" 21 | symb_black_circle = u"\u25cf" 22 | symb_stop = u"\U0001f6ab" 23 | symb_exclamation = u"\u2757" 24 | 25 | symb_left_arraow = u"\u25c4" 26 | symb_right_arrow = u"\u25ba" 27 | 28 | 29 | def makebold(text, surround="select", translate=False): 30 | 31 | if surround == "select": 32 | before = "|| " + " " 33 | after = " " + " ||" 34 | elif surround == "hotswap": 35 | before = "|| " + symb_fire + " " 36 | after = " " + symb_fire + " ||" 37 | elif surround == "last_level": 38 | before = " " + symb_stop 39 | after = " " + symb_stop 40 | elif surround == "list": 41 | before = symb_blue_diamond_small + " " 42 | after = "" 43 | elif surround == "no": 44 | before = "" 45 | after = "" 46 | if translate: 47 | target = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 48 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 49 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 50 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 51 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '?', '.', 52 | ',', '"', "'", "|"] 53 | 54 | transl = [u'\uff41', u'\uff42', u'\uff43', u'\uff44', u'\uff45', 55 | u'\uff46', u'\uff47', u'\uff48', u'\uff49', u'\uff4a', 56 | u'\uff4b', u'\uff4c', u'\uff4d', u'\uff4e', u'\uff4f', 57 | u'\uff50', u'\uff51', u'\uff52', u'\uff53', u'\uff54', 58 | u'\uff55', u'\uff56', u'\uff57', u'\uff58', u'\uff59', 59 | u'\uff5a', u'\uff21', u'\uff22', u'\uff23', u'\uff24', 60 | u'\uff25', u'\uff26', u'\uff27', u'\uff28', u'\uff29', 61 | u'\uff2a', u'\uff2b', u'\uff2c', u'\uff2d', u'\uff2e', 62 | u'\uff2f', u'\uff30', u'\uff31', u'\uff32', u'\uff33', 63 | u'\uff34', u'\uff35', u'\uff36', u'\uff37', u'\uff38', 64 | u'\uff39', u'\uff3a', u'\uff10', u'\uff11', u'\uff12', 65 | u'\uff13', u'\uff14', u'\uff15', u'\uff16', u'\uff17', 66 | u'\uff18', u'\uff19', u'\uff01', u'\uff1f', u'\uff0e', 67 | u'\uff0c', u'"', u'\uff07', u'\uff5c'] 68 | translated = "" 69 | for i in text: 70 | try: 71 | translated += transl[target.index(i)] 72 | except Exception: 73 | translated += i 74 | else: 75 | translated = text 76 | 77 | return before + translated + after 78 | # fmt: on 79 | 80 | 81 | class dummy_item(object): 82 | def __init__(self, name, children): 83 | self.name = name 84 | self.children = list(children) 85 | self.is_loadable = False 86 | self.is_folder = True 87 | self.is_device = False 88 | self.source = "QBrowser" 89 | self.uri = "QBrowser#top-level" 90 | 91 | 92 | # class QSequencer(ControlSurface): 93 | class QBrowser(object): 94 | def __init__(self, parent): 95 | self._parent = parent 96 | 97 | self.up_down = True 98 | 99 | self.button_colors = {} 100 | 101 | self.pointer = 0 102 | self.parent_pointer = [] 103 | 104 | self.browser_item = self.app.browser.instruments 105 | self.parent_item = [] 106 | 107 | # encoder turn sensitivity 108 | self.sensitivity = 6 109 | 110 | self.itemlist = self._get_itemlist() 111 | self.names = self._get_names() 112 | 113 | self.preview_items = False 114 | self.hotswap = False 115 | 116 | self._ableton_version = self.app.get_major_version() 117 | 118 | # -------------------------- 119 | 120 | @property 121 | def song(self): 122 | return self._parent._parent.song() 123 | 124 | @property 125 | def app(self): 126 | return self._parent._parent.application() 127 | 128 | # -------------------------- 129 | 130 | @property 131 | def sounds(self): 132 | return self.app.browser.sounds 133 | 134 | @property 135 | def drums(self): 136 | return self.app.browser.drums 137 | 138 | @property 139 | def instruments(self): 140 | return self.app.browser.instruments 141 | 142 | @property 143 | def audio_effects(self): 144 | return self.app.browser.audio_effects 145 | 146 | @property 147 | def midi_effects(self): 148 | return self.app.browser.midi_effects 149 | 150 | @property 151 | def samples(self): 152 | return self.app.browser.samples 153 | 154 | @property 155 | def collections(self): 156 | return dummy_item("Collections", self.app.browser.colors) 157 | 158 | @property 159 | def plugins(self): 160 | return self.app.browser.plugins 161 | 162 | @property 163 | def max_for_live(self): 164 | return self.app.browser.max_for_live 165 | 166 | @property 167 | def clips(self): 168 | return self.app.browser.clips 169 | 170 | # -------------------------- 171 | 172 | @property 173 | def hotswap_target(self): 174 | return self.app.browser.hotswap_target 175 | 176 | # TODO implement grooves via Live.GroovePool 177 | @property 178 | def _itemlist(self): 179 | itemlist = [ 180 | self.sounds, 181 | self.drums, 182 | self.instruments, 183 | self.audio_effects, 184 | self.midi_effects, 185 | self.plugins, 186 | self.clips, 187 | self.samples, 188 | self.max_for_live, 189 | ] 190 | 191 | # make sure collections is the last entry 192 | itemlist.append(self.collections) 193 | return itemlist 194 | 195 | @property 196 | def _level0_names(self): 197 | return [i.name for i in self._itemlist] 198 | 199 | @property 200 | def _itemlist_names(self): 201 | return dict( 202 | clips=[self.samples.name], 203 | instruments=[ 204 | self.sounds.name, 205 | self.instruments.name, 206 | self.drums.name, 207 | self.plugins.name, 208 | ], 209 | audio_effects=[self.audio_effects.name], 210 | midi_effects=[self.midi_effects.name], 211 | special=[self.collections.name], 212 | ) 213 | 214 | def _get_itemlist(self): 215 | if len(self.parent_item) == 0: 216 | itemlist = self._itemlist 217 | 218 | else: 219 | itemlist = list(self.parent_item[-1].children) 220 | 221 | return itemlist 222 | 223 | def _scroll_browser(self, up_down, direction="up_down"): 224 | app = self.app 225 | 226 | if not app.view.is_view_visible("Browser"): 227 | app.view.show_view("Browser") 228 | app.view.focus_view("Browser") 229 | 230 | if up_down: 231 | if direction == "up_down": 232 | app.view.scroll_view(NavDirection.up, "Browser", False) 233 | elif direction == "left_right": 234 | app.view.scroll_view(NavDirection.left, "Browser", False) 235 | else: 236 | if direction == "up_down": 237 | app.view.scroll_view(NavDirection.down, "Browser", False) 238 | elif direction == "left_right": 239 | app.view.scroll_view(NavDirection.right, "Browser", False) 240 | 241 | def next_level(self, empty=False): 242 | itemlist = list(self.browser_item.children) 243 | if len(itemlist) > 0: 244 | # if self.hotswap: 245 | # self._scroll_browser(False, direction="left_right") 246 | # self._scroll_browser(False, direction="up_down") 247 | 248 | self.parent_item.append(self.browser_item) 249 | self.parent_pointer.append(self.pointer) 250 | 251 | if empty: 252 | self._print_info(empty=empty) 253 | 254 | self.pointer = 0 255 | 256 | self.browser_item = itemlist[self.pointer] 257 | 258 | self.itemlist = self._get_itemlist() 259 | self.names = self._get_names() 260 | 261 | if not empty: 262 | self._print_info(empty=empty) 263 | 264 | else: 265 | self._print_info(empty=True, surround_selected="last_level") 266 | 267 | def prev_level(self): 268 | 269 | if len(self.parent_item) > 0: 270 | 271 | # if self.hotswap: 272 | # # do this twice to close the open folder 273 | # self._scroll_browser(True, direction="left_right") 274 | # self._scroll_browser(True, direction="left_right") 275 | 276 | self.browser_item = self.parent_item.pop(-1) 277 | 278 | self.pointer = self.parent_pointer.pop(-1) 279 | 280 | self.itemlist = self._get_itemlist() 281 | self.names = self._get_names() 282 | 283 | self._print_info(empty=False) 284 | 285 | def scroll_up(self): 286 | 287 | # clear any remaining send-messages 288 | self._parent._parent._task_group.clear() 289 | 290 | nitems = len(self.itemlist) 291 | if self.pointer < nitems - 1: 292 | self.pointer += 1 293 | 294 | # if self.hotswap: 295 | # self._scroll_browser(False, direction="up_down") 296 | 297 | self.browser_item = self.itemlist[self.pointer] 298 | self._print_info() 299 | 300 | if self.preview_items: 301 | self.app.browser.stop_preview() 302 | self._preview_item() 303 | 304 | def scroll_down(self): 305 | 306 | # clear any remaining send-messages 307 | self._parent._parent._task_group.clear() 308 | 309 | if self.pointer > 0: 310 | self.pointer -= 1 311 | 312 | # if self.hotswap: 313 | # self._scroll_browser(True, direction="up_down") 314 | 315 | self.browser_item = self.itemlist[self.pointer] 316 | self._print_info() 317 | 318 | if self.preview_items: 319 | self.app.browser.stop_preview() 320 | self._preview_item() 321 | 322 | def scroll_item(self, value): 323 | 324 | # clear any remaining send-messages 325 | self._parent._parent._task_group.clear() 326 | 327 | nitems = len(self.itemlist) 328 | if value < 65: 329 | if self.pointer < nitems - 1: 330 | self.pointer += 1 331 | # if self.hotswap: 332 | # self._scroll_browser(False, direction="up_down") 333 | 334 | else: 335 | if self.pointer > 0: 336 | self.pointer -= 1 337 | # if self.hotswap: 338 | # self._scroll_browser(True, direction="up_down") 339 | 340 | self.browser_item = self.itemlist[self.pointer] 341 | 342 | self._print_info() 343 | 344 | if self.preview_items: 345 | self.app.browser.stop_preview() 346 | self._preview_item() 347 | 348 | def _get_names(self): 349 | names = [] 350 | for item in self.itemlist: 351 | n = item.name 352 | 353 | if item.is_folder: 354 | n = symb_folder + " " + n 355 | elif item.is_device: 356 | n = symb_blue_diamond_small + " " + n 357 | else: 358 | n = symb_black_circle + " " + n 359 | 360 | names.append(n) 361 | 362 | return names 363 | 364 | def _print_info( 365 | self, 366 | empty=False, 367 | surround_selected="select", 368 | surround_all=None, 369 | sel_nchar=0, 370 | l_r_nchar=80, 371 | sep=" ", 372 | space=" ", 373 | ): 374 | """ 375 | 376 | Parameters 377 | ---------- 378 | empty : bool, optional 379 | print whitespaces instead of text. The default is False. 380 | surround_selected : str, optional 381 | makebold() applied to the selected item 382 | The default is "select". 383 | surround_all : str, optional 384 | makebold() applied to all names 385 | The default is None. 386 | sel_nchar : int, optional 387 | min. number of characters for the selected string. 388 | The default is 40. 389 | l_r_nchar : int, optional 390 | additional characters printed left-and right. 391 | (filled with available item names) 392 | The default is 50. 393 | sep : str, optional 394 | separator for additional elements 395 | space: str, optional 396 | space-character 397 | """ 398 | 399 | # don't print the info if browser is no longer active 400 | if not self._parent._browser: 401 | return 402 | 403 | if surround_all is not None: 404 | names = [makebold(i, surround=surround_all) for i in self.names] 405 | else: 406 | names = self.names 407 | 408 | before = sep.join(names[: self.pointer]) + sep 409 | after = sep + sep.join(names[self.pointer + 1 :]) 410 | 411 | if self.hotswap: 412 | surround_selected = "hotswap" 413 | 414 | selected = names[self.pointer] 415 | if self.browser_item.is_loadable: 416 | if self.hotswap: 417 | selected = symb_circle_arrow + selected[selected.index(" ") :] 418 | else: 419 | selected = symb_red_circle + selected[selected.index(" ") :] 420 | else: 421 | selected = symb_orange_circle + selected[selected.index(" ") :] 422 | 423 | if empty: 424 | before = space * len(before) 425 | after = "" 426 | 427 | # number of additional text on left- and right side 428 | nchar = l_r_nchar - len(selected) // 2 429 | 430 | outstr = ( 431 | before[-nchar:].rjust(nchar, space) 432 | + makebold( 433 | selected.upper(), surround=surround_selected, translate=True 434 | ).center(sel_nchar, space) 435 | + after[:nchar].ljust(nchar, space) 436 | ) 437 | 438 | folder = ( 439 | symb_folder 440 | + sep 441 | + (sep + "|" + sep + symb_folder_open).join( 442 | [i.name for i in self.parent_item] 443 | ) 444 | + ":" 445 | + sep * 5 446 | ) 447 | 448 | self._parent._parent.show_message(folder + makebold(outstr, surround="no")) 449 | 450 | # continue updating the info-bar unil the browser is closed 451 | if self._parent._browser: 452 | self._parent._parent.schedule_message(16, self._print_info) 453 | 454 | def _load_item(self): 455 | try: 456 | self._print_info(empty=True) 457 | self.app.browser.load_item(self.browser_item) 458 | except Exception: 459 | self._parent._parent.show_message( 460 | " " 461 | + symb_stop 462 | + " the item " 463 | + str(self.browser_item.name) 464 | + " could not be loaded" 465 | ) 466 | 467 | if self.hotswap: 468 | self._hide_browser() 469 | self._print_info() 470 | 471 | try: 472 | 473 | def cb(): 474 | try: 475 | track = self.song.view.selected_track 476 | device = track.view.selected_device 477 | self.app.browser.hotswap_target = device 478 | except Exception: 479 | self._parent._parent.log_message("couldn't set hotswap target") 480 | 481 | self._parent._parent.schedule_message(4, cb) 482 | except Exception: 483 | self._parent._parent.schedule_message(2, cb) 484 | 485 | def _toggle_preview_item(self): 486 | 487 | self.preview_items = not self.preview_items 488 | 489 | if not self.preview_items: 490 | self.app.browser.stop_preview() 491 | else: 492 | self._preview_item() 493 | 494 | def _preview_item(self): 495 | try: 496 | self.app.browser.preview_item(self.browser_item) 497 | except Exception: 498 | self._parent._parent.show_message( 499 | " " 500 | + symb_stop 501 | + "the item " 502 | + str(self.browser_item.name) 503 | + " could not be previewed" 504 | ) 505 | 506 | def button_callback(self, i): 507 | """ 508 | the callback for button i (e.g. 1 - 16) 509 | """ 510 | 511 | if self._parent._shift_pressed: 512 | # use fuctionality of CONTROL layer 513 | if i == 0: 514 | self._parent._redo() 515 | elif i == 1: 516 | self._parent._collapse_device() 517 | elif i == 2: 518 | self._parent._toggle_device_on_off() 519 | elif i == 3: 520 | pass 521 | elif i == 4: 522 | pass 523 | elif i == 5: 524 | self._parent._change_quantization() 525 | elif i == 6: 526 | self._parent._change_ableton_view(next(self._parent._detail_cycle)) 527 | elif i == 7: 528 | self._parent._scroll_device_chain(0, sensitivity=1) 529 | # ---------- 530 | elif i == 8: 531 | self._parent._undo() 532 | elif i == 9: 533 | self._parent._duplicate_track() 534 | elif i == 10: 535 | self._parent._duplicate_scene() 536 | elif i == 11: 537 | self._parent._tap_tempo() 538 | elif i == 12: 539 | self._parent._toggle_metronome() 540 | elif i == 13: 541 | self._parent._toggle_automation() 542 | elif i == 14: 543 | self._load_on_new_track() 544 | elif i == 15: 545 | self._parent._scroll_device_chain(127, sensitivity=1) 546 | return 547 | else: 548 | 549 | if i == 0: 550 | self._select_item(self._level0_names.index(self.sounds.name), [], []) 551 | elif i == 1: 552 | self._select_item(self._level0_names.index(self.drums.name), [], []) 553 | elif i == 2: 554 | self._select_item( 555 | self._level0_names.index(self.instruments.name), [], [] 556 | ) 557 | elif i == 3: 558 | self._select_item( 559 | self._level0_names.index(self.audio_effects.name), [], [] 560 | ) 561 | elif i == 4: 562 | self._select_item( 563 | self._level0_names.index(self.midi_effects.name), [], [] 564 | ) 565 | elif i == 5: 566 | self._select_item(self._level0_names.index(self.samples.name), [], []) 567 | elif i == 6: 568 | self._select_item( 569 | self._level0_names.index(self.collections.name), [], [] 570 | ) 571 | elif i == 7: 572 | self._parent._select_next_track() 573 | # --- 574 | elif i == 8: 575 | self.scroll_down() 576 | elif i == 9: 577 | self.scroll_up() 578 | elif i == 10: 579 | self.prev_level() 580 | elif i == 11: 581 | self.next_level() 582 | elif i == 12: 583 | self._toggle_hotswap() 584 | elif i == 13: 585 | self._toggle_preview_item() 586 | elif i == 14: 587 | self._load_item() 588 | elif i == 15: 589 | self._parent._select_prev_track() 590 | 591 | if i in range(7): 592 | # enter the folder 593 | self.next_level(empty=True) 594 | 595 | # clear remaining scheduled messages 596 | self._parent._parent._task_group.clear() 597 | # after a delay of 10 ticks, show the folder content 598 | self._parent._parent.schedule_message(8, self._print_info) 599 | 600 | self.get_button_colors() 601 | 602 | self._parent._update_lights() 603 | 604 | def encoder_callback(self, i, value): 605 | 606 | if i == 4: 607 | self._parent._track_send_x(value, -1, 0) 608 | elif i == 5: 609 | self._parent._track_send_x(value, -1, 2) 610 | elif i == 6: 611 | self._parent._track_volume_master_or_current(value) 612 | elif i == 7: 613 | if self._parent._shift_pressed: 614 | self._parent._scroll_drum_pad_row(value) 615 | else: 616 | self._parent._select_prev_next_track(value) 617 | elif i == 12: 618 | self._parent._track_send_x(value, -1, 1) 619 | elif i == 13: 620 | self._parent._track_send_x(value, -1, 4) 621 | elif i == 14: 622 | self._parent._track_pan_master_or_current(value) 623 | elif i == 15: 624 | if self._parent._shift_pressed: 625 | self._parent._scroll_drum_pad_col(value) 626 | else: 627 | self._parent._select_prev_next_scene(value) 628 | 629 | elif i == "transpose": 630 | self.scroll_item(value) 631 | 632 | def get_button_colors(self): 633 | self.button_colors = dict( 634 | shift="red", 635 | chan="black", 636 | store="black", 637 | recall="red", 638 | ) 639 | for i in range(16): 640 | self.button_colors[i + 1] = "black" 641 | 642 | self.button_colors[1] = "magenta" 643 | self.button_colors[2] = "magenta" 644 | self.button_colors[3] = "magenta" 645 | self.button_colors[4] = "magenta" 646 | self.button_colors[5] = "magenta" 647 | self.button_colors[6] = "magenta" 648 | self.button_colors[7] = "magenta" 649 | 650 | self.button_colors[9] = "blue" 651 | self.button_colors[10] = "blue" 652 | self.button_colors[11] = "magenta" 653 | self.button_colors[12] = "magenta" 654 | 655 | if self.hotswap: 656 | self.button_colors[13] = "red" 657 | else: 658 | self.button_colors[13] = "black" 659 | 660 | if self.preview_items: 661 | self.button_colors[14] = "blue" 662 | else: 663 | self.button_colors[14] = "black" 664 | 665 | self.button_colors[15] = "red" 666 | 667 | def _hide_browser(self): 668 | self._parent._parent.schedule_message( 669 | 2, lambda: self.app.view.hide_view("Browser") 670 | ) 671 | self._parent._parent.schedule_message( 672 | 4, lambda: self.app.view.hide_view("Browser") 673 | ) 674 | self._parent._parent.schedule_message( 675 | 8, lambda: self.app.view.hide_view("Browser") 676 | ) 677 | 678 | def _toggle_hotswap(self): 679 | self.hotswap = not self.hotswap 680 | 681 | if self.hotswap: 682 | device = self._parent.selected_track.view.selected_device 683 | 684 | if device is None: 685 | self._parent._parent.show_message( 686 | " " + symb_stop + "cannot activate hotswap without a target" 687 | ) 688 | self.hotswap = False 689 | return 690 | 691 | self.app.browser.hotswap_target = device 692 | self.app.view.show_view("Detail/DeviceChain") 693 | 694 | self.find_device(device) 695 | else: 696 | self.app.browser.hotswap_target = None 697 | 698 | self._hide_browser() 699 | self._print_info() 700 | 701 | def _select_item(self, pointer, parent_pointer, parent_item): 702 | try: 703 | self.pointer = pointer 704 | self.parent_pointer = parent_pointer 705 | self.parent_item = parent_item 706 | 707 | self.itemlist = self._get_itemlist() 708 | self.names = self._get_names() 709 | self.browser_item = self.itemlist[self.pointer] 710 | 711 | self._print_info() 712 | except Exception: 713 | self._parent._parent.show_message("the item could not be selected") 714 | 715 | def find_device(self, device, select=True): 716 | folders = self._itemlist[:-1] 717 | # returns indexes of the sub-level structure 718 | parent_pointer = [] 719 | parent_item = [] 720 | 721 | def get_nested_elements(folders, device): 722 | device_found = [ 723 | i 724 | for i, dev in enumerate(folders) 725 | if self.app.browser.relation_to_hotswap_target(dev) == Relation.equal 726 | ] 727 | 728 | if len(device_found) > 0: 729 | yield device_found[0] 730 | else: 731 | for i, node in enumerate(folders): 732 | if hasattr(node, "children") and len(node.children) > 0: 733 | parent_pointer.append(i) 734 | parent_item.append(node) 735 | 736 | for e in get_nested_elements(node.children, device): 737 | yield e 738 | if len(parent_pointer) > 0: 739 | parent_pointer.pop(-1) 740 | parent_item.pop(-1) 741 | 742 | try: 743 | pointer = next(get_nested_elements(folders, device)) 744 | 745 | if select is True: 746 | self._select_item(pointer, parent_pointer, parent_item) 747 | else: 748 | return pointer, parent_pointer, parent_item 749 | 750 | except Exception: 751 | self._parent._parent.show_message( 752 | " " + symb_stop + " could not find the device " + str(device.name) 753 | ) 754 | 755 | def _find_item(self, item, select=True): 756 | folders = self._itemlist[:-1] 757 | # returns indexes of the sub-level structure 758 | parent_pointer = [] 759 | parent_item = [] 760 | 761 | def get_nested_elements(folders, item): 762 | device_found = [i for i, dev in enumerate(folders) if dev.name == item.name] 763 | 764 | if len(device_found) > 0: 765 | yield device_found[0] 766 | else: 767 | for i, node in enumerate(folders): 768 | if hasattr(node, "children") and len(node.children) > 0: 769 | parent_pointer.append(i) 770 | parent_item.append(node) 771 | 772 | for e in get_nested_elements(node.children, item): 773 | yield e 774 | if len(parent_pointer) > 0: 775 | parent_pointer.pop(-1) 776 | parent_item.pop(-1) 777 | 778 | try: 779 | pointer = next(get_nested_elements(folders, item)) 780 | 781 | if select is True: 782 | self._select_item(pointer, parent_pointer, parent_item) 783 | else: 784 | return pointer, parent_pointer, parent_item 785 | 786 | except AssertionError: 787 | self._parent._parent.show_message( 788 | "could not find the device " + str(item.name) 789 | ) 790 | 791 | def identify_item(self): 792 | 793 | if len(self.parent_item) > 0: 794 | parent = self.parent_item[0].name 795 | ID = "UNKNOWN" 796 | 797 | for key, val in self._itemlist_names.items(): 798 | if parent in val: 799 | ID = key 800 | 801 | if ID == "special": 802 | 803 | try: 804 | _, _, parent_item = self._find_item(self.browser_item, select=False) 805 | if len(parent_item) > 0: 806 | ID = parent_item[0].name 807 | else: 808 | ID = "UNKNOWN" 809 | except Exception: 810 | ID = "UNKNOWN" 811 | 812 | self._parent._parent.show_message( 813 | " " + symb_stop + "item not found... please create track manually" 814 | ) 815 | 816 | return ID 817 | 818 | def _load_on_new_track(self): 819 | ID = self.identify_item() 820 | if ID == "audio_effects" or ID == "midi_effects": 821 | self.song.create_return_track() 822 | self._load_item() 823 | elif ID == "instruments": 824 | self.song.create_midi_track() 825 | self._load_item() 826 | elif ID == "clips": 827 | self.song.create_audio_track() 828 | self._load_item() 829 | else: 830 | self._parent._parent.show_message( 831 | "could not establish the type of " 832 | + str(self.browser_item.name) 833 | + " ... please create the appropriate" 834 | + "track manually" 835 | ) 836 | -------------------------------------------------------------------------------- /QSequencer.py: -------------------------------------------------------------------------------- 1 | import Live 2 | from .QSetup import QSetup 3 | import time 4 | 5 | # fmt: off 6 | symb_voltage = u"\u26A1" 7 | symb_blue_diamond_small = u"\U0001f539" 8 | symb_blue_diamond_large = u"\U0001F537" 9 | symb_white_diamond = u"\u25c7" 10 | symb_red_circle = u"\U0001f534" 11 | 12 | symb_stop = u"\U0001f6ab" 13 | symb_exclamation = u"\u2757" 14 | empty_square = u"\u2591" 15 | v_bars = [u"\u2582", u"\u2584", u"\u2586", u"\u2588"] 16 | 17 | # fmt: on 18 | 19 | # add this to be able to print nice Fractions (without using the "fractions" module) 20 | 21 | 22 | def gcd(a, b): 23 | """Calculate the Greatest Common Divisor of a and b. 24 | 25 | Unless b==0, the result will have the same sign as b (so that when 26 | b is divided by it, the result comes out positive). 27 | """ 28 | while b: 29 | a, b = b, a % b 30 | return a 31 | 32 | 33 | def simplify_fraction(numer, denom): 34 | # This is required since abletons python does not provide the "fractions" module 35 | # adapted from https://codereview.stackexchange.com/a/66474 36 | if denom == 0: 37 | return "Division by 0 - result undefined" 38 | # Remove greatest common divisor: 39 | common_divisor = gcd(numer, denom) 40 | (reduced_num, reduced_den) = (numer / common_divisor, denom / common_divisor) 41 | # Note that reduced_den > 0 as documented in the gcd function. 42 | if reduced_den == 1: 43 | return f"{reduced_num:.0f}" 44 | elif common_divisor == 1: 45 | return f"{numer:.0f}/{denom:.0f}" 46 | else: 47 | return f"{reduced_num:.0f}/{reduced_den:.0f}" 48 | 49 | 50 | # class QSequencer(ControlSurface): 51 | class QSequencer(object): 52 | def __init__(self, parent): 53 | self._parent = parent 54 | 55 | self._encoder_up_counter = { 56 | **{i: 0 for i in range(16)}, "transpose": 0} 57 | self._encoder_down_counter = { 58 | **{i: 0 for i in range(16)}, "transpose": 0} 59 | self.QS = QSetup() 60 | 61 | self.up_down = True 62 | 63 | self.change_property = "pitch" 64 | self.change_interval = 1 65 | self.change_min = 0 66 | self.change_max = 128 67 | self.sensitivity = 8 68 | 69 | self.button_colors = {} 70 | 71 | self.blinkcolor = "red" 72 | self.mutecolor = "black" 73 | self.notecolor = "magenta" 74 | self.loopcolor = "blue" 75 | 76 | self._activeslot = 1 77 | self.noterange = "all" 78 | 79 | self.sequence_length = 8 80 | 81 | self.adjust_fine = 0.05 82 | self.adjust_coarse = 0.5 83 | 84 | self.n_notes = 16 85 | self.note_duration = 0.5 86 | self.note_offset = 0 87 | self.note_velocity = 0.75 88 | 89 | self._assigned_notes = set() 90 | self._singlebutton = True 91 | self._doit = True 92 | 93 | self.sequence_lengths = [1, 2, 4, 8, 16, 32, 64, 128] 94 | # [2,1,1/2,1/4,1/8,1/16,1/32] 95 | 96 | self.note_offset_duration = [True, True, False, False] 97 | 98 | self.note_velocities = [0.25, 0.5, 0.75, 1] 99 | 100 | self.sequence_names = { 101 | i: f"{simplify_fraction(i, 16 * 4)}".ljust(4, "_") + "_Q" 102 | for i in self.sequence_lengths 103 | } 104 | self.sequence_names_inverted = dict( 105 | (v, k) for k, v in self.sequence_names.items() 106 | ) 107 | 108 | self.sequence_up = 0 109 | self.sequence_n = 4 110 | 111 | @property 112 | def song(self): 113 | return self._parent._parent.song() 114 | 115 | @property 116 | def clip_slot(self): 117 | return self.song.view.highlighted_clip_slot 118 | 119 | @property 120 | def clip(self): 121 | if self.clip_slot is not None: 122 | if self.clip_slot.has_clip: 123 | return self.clip_slot.clip 124 | else: 125 | return None 126 | else: 127 | return None 128 | 129 | def dotheblink(self): 130 | if self.clip is not None and self._parent._sequencer: 131 | i = 1 + (int(self.clip.playing_position * 132 | 16 / self.sequence_length) % 16) 133 | if self._activeslot == i: 134 | return 135 | else: 136 | self._parent._update_lights() 137 | # blink only if slot has changed 138 | self._parent._set_color(i, self.blinkcolor) 139 | 140 | self._activeslot = i 141 | 142 | def _highlite_loop(self): 143 | self.get_button_colors() 144 | self._parent._update_lights() 145 | 146 | def add_handler(self): 147 | self.get_button_colors() 148 | self._parent._update_lights() 149 | 150 | if self.clip is not None: 151 | # Loop listener 152 | if not self.clip.loop_start_has_listener(self._highlite_loop): 153 | self.clip.add_loop_start_listener(self._highlite_loop) 154 | if not self.clip.loop_end_has_listener(self._highlite_loop): 155 | self.clip.add_loop_end_listener(self._highlite_loop) 156 | if not self.clip.position_has_listener(self._highlite_loop): 157 | self.clip.add_position_listener(self._highlite_loop) 158 | # Notes listener 159 | if not self.clip.notes_has_listener(self._parent._update_lights): 160 | self.clip.add_notes_listener(self._parent._update_lights) 161 | # Playing position listener 162 | if not self.clip.playing_position_has_listener(self.dotheblink): 163 | self.clip.add_playing_position_listener(self.dotheblink) 164 | 165 | self.get_sequence_length() 166 | self.get_n_notes() 167 | 168 | def remove_handler(self): 169 | if self.clip is not None: 170 | # Loop listener 171 | if self.clip.loop_start_has_listener(self._highlite_loop): 172 | self.clip.remove_loop_start_listener(self._highlite_loop) 173 | if self.clip.loop_end_has_listener(self._highlite_loop): 174 | self.clip.remove_loop_end_listener(self._highlite_loop) 175 | if self.clip.position_has_listener(self._highlite_loop): 176 | self.clip.remove_position_listener(self._highlite_loop) 177 | # Notes listener 178 | if self.clip.notes_has_listener(self._parent._update_lights): 179 | self.clip.remove_notes_listener(self._parent._update_lights) 180 | # Playing position listener 181 | if self.clip.playing_position_has_listener(self.dotheblink): 182 | self.clip.remove_playing_position_listener(self.dotheblink) 183 | 184 | @property 185 | def _set_encoder_prop_msg(self): 186 | if len(self._assigned_notes) > 0: 187 | self._multitouch_info_msg() 188 | else: 189 | return ( 190 | " " * 15 191 | + " changing" 192 | + " " * 20 193 | + symb_voltage 194 | + " " 195 | + str(self.change_property).upper() 196 | + " " 197 | + symb_voltage 198 | ) 199 | 200 | def set_change_properties(self, i, up_down): 201 | msg = None 202 | if i == 0: 203 | self.change_property = "pitch" 204 | self.change_interval = 1 205 | self.change_min = 0 206 | self.change_max = 127 207 | self.sensitivity = 8 208 | msg = self._set_encoder_prop_msg 209 | elif i == 1: 210 | self.change_property = "velocity" 211 | self.change_interval = 1 212 | self.sensitivity = 1 213 | self.change_min = 1 214 | self.change_max = 127 215 | msg = self._set_encoder_prop_msg 216 | elif i == 2: 217 | self.change_property = "start_time" 218 | self.change_interval = self.sequence_length / 16 * self.adjust_fine 219 | self.sensitivity = 5 220 | self.change_min = 0 221 | self.change_max = 9999 222 | msg = self._set_encoder_prop_msg 223 | elif i == 3: 224 | self.change_property = "duration" 225 | self.change_interval = self.sequence_length / 16 * self.adjust_fine 226 | self.sensitivity = 5 227 | self.change_min = 0 228 | self.change_max = 127 229 | msg = self._set_encoder_prop_msg 230 | elif i == 4: 231 | self.change_property = "velocity_deviation" 232 | self.change_interval = 1 233 | self.sensitivity = 1 234 | self.change_min = -127 235 | self.change_max = 127 236 | msg = self._set_encoder_prop_msg 237 | elif i == 5: 238 | self.change_property = "probability" 239 | self.change_interval = 0.05 240 | self.sensitivity = 5 241 | self.change_min = 0 242 | self.change_max = 1 243 | msg = self._set_encoder_prop_msg 244 | elif i == 6: 245 | pass 246 | elif i == 7: 247 | # use QControlComponent functionality 248 | pass 249 | elif i == 8: 250 | self.sensitivity = 4 251 | self.set_loop_property( 252 | up_down, "loop_start", self.sequence_length / 16 * 0.5 253 | ) 254 | elif i == 9: 255 | self.sensitivity = 4 256 | self.set_loop_property( 257 | up_down, "loop_start", self.sequence_length / 16 * self.adjust_fine 258 | ) 259 | elif i == 10: 260 | self.sensitivity = 4 261 | self.set_loop_property( 262 | up_down, "position", self.sequence_length / 16 * self.adjust_fine 263 | ) 264 | elif i == 11: 265 | self.sensitivity = 4 266 | self.set_loop_property( 267 | up_down, "loop_end", self.sequence_length / 16 * self.adjust_fine 268 | ) 269 | elif i == 12: 270 | self.sensitivity = 4 271 | self.set_loop_property( 272 | up_down, "loop_end", self.sequence_length / 16 * self.adjust_coarse 273 | ) 274 | elif i == 14: 275 | msg = None 276 | # transpose only notes inside current loop 277 | self.noterange = "loop" 278 | self.irene_transposers(up_down) 279 | 280 | if msg is not None: 281 | self._parent._parent.show_message(msg) 282 | 283 | def irene_transposers(self, up_down): 284 | if self.clip is not None: 285 | self.clip.select_all_notes() 286 | self.modify_note(range(16), up_down) 287 | 288 | self._parent._parent.show_message( 289 | " " * 15 290 | + " changing" 291 | + " " * 20 292 | + symb_voltage 293 | + " " 294 | + str(self.change_property).upper() 295 | + " " 296 | + symb_voltage 297 | + " " * 20 298 | + " of ALL notes" 299 | ) 300 | 301 | def set_sequence_up(self, up_down): 302 | if up_down: 303 | 304 | if ( 305 | self._parent._transpose_val 306 | + 16 / max(self.sequence_n, 2) * (self.sequence_up) 307 | < 127 308 | ): 309 | self.sequence_up = self.sequence_up + 1 310 | else: 311 | if ( 312 | self._parent._transpose_val 313 | + 16 / max(self.sequence_n, 2) * (self.sequence_up) 314 | > 0 315 | ): 316 | self.sequence_up = self.sequence_up - 1 317 | 318 | self.show_sequence_info() 319 | 320 | def set_sequence_n(self, up_down): 321 | if up_down: 322 | self.sequence_n = min(self.sequence_n + 1, 8) 323 | else: 324 | self.sequence_n = max(self.sequence_n - 1, 0) 325 | 326 | self.show_sequence_info() 327 | 328 | def _check_loop_prop_integrity(self, prop, val): 329 | if prop == "loop_end": 330 | start_val = getattr(self.clip, "loop_start") 331 | return start_val < val 332 | elif prop == "loop_start": 333 | end_val = getattr(self.clip, "loop_end") 334 | return end_val > val 335 | else: 336 | return True 337 | 338 | def set_loop_property(self, up_down, prop, interval): 339 | curr_val = getattr(self.clip, prop) 340 | if up_down: 341 | new_val = curr_val + interval 342 | if self._check_loop_prop_integrity(prop, new_val): 343 | setattr(self.clip, prop, new_val) 344 | else: 345 | new_val = curr_val - interval 346 | if self._check_loop_prop_integrity(prop, new_val): 347 | setattr(self.clip, prop, new_val) 348 | 349 | def button_callback(self, i, **kwargs): 350 | """ 351 | the callback for button i (e.g. 1 - 16) 352 | """ 353 | if kwargs["value"] > 0: 354 | if self._parent._shift_pressed: 355 | if i in range(1, 7): 356 | self._parent._select_track(i) 357 | elif i == 7: 358 | self._parent._select_prev_scene() 359 | elif i == 8: 360 | self._parent._undo() 361 | elif i == 9: 362 | self._parent._delete_clip() 363 | elif i == 11: 364 | self._parent._duplicate_clip() 365 | elif i == 12: 366 | self._parent._duplicate_loop() 367 | elif i == 14: 368 | self._parent._fire_record() 369 | elif i == 15: 370 | self._parent._select_next_scene() 371 | 372 | elif self.clip is None: 373 | self.set_sequence_length_button(i) 374 | self.set_note_duration_button(i) 375 | self.set_note_velocity_button(i) 376 | else: 377 | # handle long-pressing a button 378 | if kwargs["value"] > 0: 379 | self._doit = True 380 | self._assigned_notes.add(i) 381 | 382 | if len(self._assigned_notes) > 1 or not self._singlebutton: 383 | # only mute notes if the button has been pressed alone 384 | self._doit = False 385 | self._singlebutton = False 386 | else: 387 | self._doit = True 388 | 389 | elif kwargs["value"] == 0: 390 | if self.clip is not None: 391 | # remove released buttons from _assigned_notes 392 | # if no buttons are pressed any longer, reset _singlebutton 393 | try: 394 | self._assigned_notes.remove(i) 395 | except KeyError: 396 | pass 397 | 398 | if len(self._assigned_notes) == 0: 399 | self._singlebutton = True 400 | 401 | # if the button is released and no other buttons have been pressed, 402 | # mute/unmute it 403 | if self._doit: 404 | # self.clip.scrub(self.sequence_length / 16 * i) 405 | # self.clip.stop_scrub() 406 | 407 | self.clip.select_all_notes() 408 | self.modify_note( 409 | assigned_notes={i}, 410 | mute=not self.get_note_specs(i=i, name="mute"), 411 | ) 412 | self._singlebutton = True 413 | self._assigned_notes.clear() 414 | 415 | if self.clip is not None: 416 | # if a button is pressed a duration of 3 ticks, activate note-edit mode 417 | self._parent._parent.schedule_message(3, self._multitouch_info_msg) 418 | self.get_button_colors() 419 | 420 | def _multitouch_info_msg(self): 421 | self._doit = False 422 | if len(self._assigned_notes) > 0: 423 | notevector, notes = self.get_notes() 424 | 425 | if notevector is None: 426 | return 427 | 428 | s = "" 429 | for i, note in enumerate(notes[:16]): 430 | if i == 8: 431 | s += " | " 432 | if i in [4, 12]: 433 | s += " " 434 | if i in self._assigned_notes: 435 | s += symb_red_circle 436 | else: 437 | if note.mute: 438 | s += symb_white_diamond + " " 439 | else: 440 | s += symb_blue_diamond_large 441 | 442 | self._parent._parent.show_message( 443 | " " * 15 444 | + " changing" 445 | + " " * 20 446 | + symb_voltage 447 | + " " 448 | + str(self.change_property).upper() 449 | + " " 450 | + symb_voltage 451 | + " " * 20 452 | + "of notes" 453 | + " " * 20 454 | + s 455 | ) 456 | 457 | # keep message alive until all buttons are released 458 | self._parent._parent.schedule_message( 459 | 16, self._multitouch_info_msg) 460 | else: 461 | self._parent._parent._task_group.clear() 462 | self._parent._parent.show_message(" ") 463 | 464 | def encoder_callback(self, i, value): 465 | # use encoders 8 & 16 for normal scenes/tracks/drumrack navigation 466 | if i == 7: 467 | if self._parent._shift_pressed: 468 | self._parent._scroll_drum_pad_row(value) 469 | else: 470 | self._parent._select_prev_next_track(value) 471 | return 472 | elif i == 15: 473 | if self._parent._shift_pressed: 474 | self._parent._scroll_drum_pad_col(value) 475 | else: 476 | self._parent._select_prev_next_scene(value) 477 | return 478 | 479 | up_down = value < 64 480 | self.noterange = "all" 481 | 482 | # do this to avoid jumping around 483 | if up_down: 484 | for key in self._encoder_down_counter.keys(): 485 | self._encoder_down_counter[key] = 0 486 | self._counter = self._encoder_up_counter 487 | else: 488 | for key in self._encoder_up_counter.keys(): 489 | self._encoder_up_counter[key] = 0 490 | self._counter = self._encoder_down_counter 491 | 492 | # increase the counter 493 | self._counter[i] = self._counter[i] + 1 494 | 495 | if self.clip is None: 496 | if i == "transpose": 497 | self._parent._transpose(value, set_values=False) 498 | elif i in [0, 1, 2, 3, 4, 5]: 499 | self.set_change_properties(i, up_down) 500 | 501 | elif i == 8: 502 | if self._counter[i] > self.sensitivity: 503 | self.set_sequence_up(up_down) 504 | 505 | # set all counters to zero 506 | for key in self._encoder_down_counter.keys(): 507 | self._encoder_down_counter[key] = 0 508 | self._encoder_up_counter[key] = 0 509 | 510 | elif i == 9: 511 | if self._counter[i] > self.sensitivity: 512 | self.set_sequence_n(up_down) 513 | 514 | # set all counters to zero 515 | for key in self._encoder_down_counter.keys(): 516 | self._encoder_down_counter[key] = 0 517 | self._encoder_up_counter[key] = 0 518 | return 519 | 520 | if not self._parent._shift_pressed and i != "transpose": 521 | self.clip.select_all_notes() 522 | self.set_change_properties(i, up_down) 523 | return 524 | 525 | if self._counter[i] > self.sensitivity: 526 | if i == "transpose": 527 | if len(self._assigned_notes) > 0: 528 | self.modify_note(self._assigned_notes, up_down) 529 | self._doit = False 530 | else: 531 | self.irene_transposers(up_down) 532 | 533 | elif self._parent._shift_pressed: 534 | self.modify_note([i], up_down) 535 | # set all counters to zero 536 | for key in self._encoder_down_counter.keys(): 537 | self._encoder_down_counter[key] = 0 538 | self._encoder_up_counter[key] = 0 539 | 540 | def get_button_colors(self): 541 | if self.clip is None: 542 | self.button_colors = dict( 543 | shift="black", 544 | chan="red", 545 | store="black", 546 | recall="black", 547 | ) 548 | else: 549 | self.button_colors = dict( 550 | shift="black", 551 | chan="red", 552 | store="red", 553 | recall="red", 554 | ) 555 | 556 | for i in range(16): 557 | self.button_colors[i + 1] = "black" 558 | 559 | if self.clip is not None: 560 | 561 | notevector, notes = self.get_notes() 562 | 563 | if notevector is not None: 564 | for i, note in enumerate(notes): 565 | if note.mute: 566 | self.button_colors[i + 1] = self.mutecolor 567 | else: 568 | if ( 569 | note.start_time >= self.clip.loop_start 570 | and note.start_time < self.clip.loop_end 571 | ): 572 | self.button_colors[i + 1] = self.loopcolor 573 | else: 574 | self.button_colors[i + 1] = self.notecolor 575 | if i < 15: 576 | self.button_colors[i + 2] = self.notecolor 577 | 578 | if len(self._assigned_notes) > 0: 579 | for i in self._assigned_notes: 580 | self.button_colors[i + 1] = "red" 581 | else: 582 | self.button_colors[ 583 | self.sequence_lengths.index(self.sequence_length) + 1 584 | ] = "red" 585 | 586 | for i, offset_Q in enumerate(self.note_offset_duration): 587 | if offset_Q: 588 | self.button_colors[i + 8 + 1] = "magenta" 589 | 590 | for i in range(13, self.note_velocities.index(self.note_velocity) + 14): 591 | self.button_colors[i] = "blue" 592 | 593 | # ------------------------------------------- 594 | 595 | def add_note( 596 | self, 597 | pitch, 598 | start_time, 599 | duration, 600 | velocity, 601 | velocity_deviation, 602 | probability, 603 | mute, 604 | ): 605 | """ 606 | add new notes to the currently selected clip 607 | """ 608 | if pitch > 127 or velocity > 127 or probability > 1: 609 | return 610 | 611 | note = Live.Clip.MidiNoteSpecification( 612 | pitch=pitch, 613 | start_time=start_time, 614 | duration=duration, 615 | velocity=velocity, 616 | velocity_deviation=velocity_deviation, 617 | probability=probability, 618 | mute=mute, 619 | ) 620 | 621 | if self.clip is not None: 622 | self.clip.add_new_notes((note,)) 623 | 624 | def get_notes(self): 625 | """ 626 | get all notes of the current clip or the notes inside 627 | the current loop (depending on self.noterange) 628 | """ 629 | 630 | if self.clip is not None: 631 | if self.noterange == "loop": 632 | notevector = self.clip.get_notes_extended( 633 | 0, 634 | 128, 635 | self.clip.loop_start, 636 | self.clip.loop_end - self.clip.loop_start, 637 | ) 638 | elif self.noterange == "all": 639 | notevector = self.clip.get_notes_extended(0, 128, 0, 9999) 640 | 641 | if notevector is not None: 642 | notes = list(notevector) 643 | notes.sort(key=lambda x: x.start_time) 644 | 645 | return notevector, notes[:16] 646 | else: 647 | return None, None 648 | 649 | def modify_note(self, assigned_notes, up_down=True, **note_kwargs): 650 | notevector, notes = self.get_notes() 651 | curr_vals = self.get_note_specs(name=self.change_property) 652 | 653 | if self.clip is not None and notevector is not None: 654 | for i in assigned_notes: 655 | if len(note_kwargs) == 0: 656 | kwargs = {} 657 | 658 | curr_val = curr_vals[i] 659 | if curr_val is not None: 660 | if up_down: 661 | kwargs[self.change_property] = min( 662 | curr_val + self.change_interval, 663 | self.change_max, 664 | ) 665 | else: 666 | kwargs[self.change_property] = max( 667 | curr_val - self.change_interval, 668 | self.change_min, 669 | ) 670 | else: 671 | kwargs = note_kwargs 672 | 673 | if len(notes) > i: 674 | note = notes[i] 675 | for key, val in kwargs.items(): 676 | setattr(note, key, val) 677 | 678 | self.clip.apply_note_modifications(notevector) 679 | 680 | def get_note_specs(self, name, i=None): 681 | """[summary] 682 | returns a list of the first 16 available note-specs if i is not provided 683 | (the list is filled with "None" if less than 16 notes are available) 684 | """ 685 | notevector, notes = self.get_notes() 686 | 687 | if i is None: 688 | if notevector is not None: 689 | specs = [] 690 | for i, note in enumerate(notes): 691 | specs.append(getattr(note, name)) 692 | if i > 16: 693 | break 694 | return specs + [None]*(16 - len(specs)) 695 | else: 696 | return None 697 | else: 698 | if notevector is not None and len(notes) > i: 699 | return getattr(notes[i], name) 700 | else: 701 | return None 702 | 703 | def get_all_note_specs(self, note): 704 | return dict( 705 | pitch=note.pitch, 706 | start_time=note.start_time, 707 | duration=note.duration, 708 | velocity=note.velocity, 709 | velocity_deviation=note.velocity_deviation, 710 | probability=note.probability, 711 | ) 712 | 713 | # ------------------------------------------- 714 | 715 | def show_sequence_info(self): 716 | # keep message alive until a clip is created 717 | if self.clip is None: 718 | self._parent._parent.schedule_message(16, self.show_sequence_info) 719 | else: 720 | self._parent._parent._task_group.clear() 721 | 722 | n_velocity = self.note_velocities.index(self.note_velocity) 723 | v_symb = v_bars[n_velocity] 724 | 725 | msg = "" 726 | for i in self.note_offset_duration: 727 | if i: 728 | msg += v_symb 729 | else: 730 | msg += empty_square 731 | 732 | pitchmsg = f"(pitch {self.sequence_up} every {self.sequence_n} notes)" 733 | 734 | self._parent._parent.show_message( 735 | " " * 15 736 | + msg 737 | + " " * 15 738 | + f"{simplify_fraction(self.sequence_length, self.n_notes * 4)} BARS " 739 | + " " * 15 740 | + pitchmsg 741 | ) 742 | 743 | def set_sequence_length_button(self, i): 744 | if i < len(self.sequence_lengths): 745 | self.sequence_length = self.sequence_lengths[i] 746 | 747 | self.show_sequence_info() 748 | 749 | def set_n_notes_button(self, i): 750 | if i > 7: 751 | self.n_notes = 2 * (i - 7) 752 | 753 | self.show_sequence_info() 754 | 755 | def set_note_duration_button(self, i): 756 | if i > 7 and i < 12: 757 | j = i - 8 758 | 759 | if j - 1 >= 0: 760 | prev = self.note_offset_duration[j - 1] 761 | else: 762 | prev = False 763 | 764 | currval = self.note_offset_duration[j] 765 | 766 | if j + 1 < 4: 767 | nex = self.note_offset_duration[j + 1] 768 | else: 769 | nex = False 770 | 771 | if currval: 772 | # only turn ON if NOT both neighbouring are ON and at least one is on 773 | if not (prev and nex) and sum(self.note_offset_duration) > 1: 774 | self.note_offset_duration[j] = False 775 | else: 776 | # only turn ON if one neighbouring is ON 777 | if prev or nex: 778 | self.note_offset_duration[j] = True 779 | 780 | offset = self.note_offset_duration.index(True) 781 | self.note_duration = 0 782 | for i in self.note_offset_duration[offset:]: 783 | if i: 784 | self.note_duration += 0.25 785 | 786 | self.note_offset = offset * 0.25 787 | 788 | self.show_sequence_info() 789 | 790 | def set_note_velocity_button(self, i): 791 | if i > 11 and i < 16: 792 | self.note_velocity = self.note_velocities[i - 12] 793 | 794 | self.show_sequence_info() 795 | 796 | def get_n_notes(self): 797 | if self.clip is not None: 798 | notes, notevector = self.get_notes() 799 | self.n_notes = len(notes) 800 | 801 | def get_sequence_length(self): 802 | if self.clip is not None: 803 | try: 804 | # take only first 6 characters (e.b. "1/64_Q" ) 805 | self.sequence_length = self.sequence_names_inverted[self.clip.name[:6]] 806 | self._parent._parent.show_message( 807 | "sequence tempo set to: " 808 | + f"{simplify_fraction(self.sequence_length, self.n_notes * 4)} BARS " 809 | ) 810 | except KeyError: 811 | self._parent._parent.show_message( 812 | symb_exclamation 813 | + " sequence tempo could not be parsed from clip-name..." 814 | ) 815 | pass 816 | 817 | def init_sequence(self): 818 | # show midi-clip view when sequence is initialized 819 | self._parent._change_ableton_view("Detail/Clip") 820 | 821 | if not self.clip_slot.has_clip: 822 | self.clip_slot.create_clip(self.sequence_length) 823 | 824 | sequence = self.set_sequence() 825 | 826 | for i in range(16): 827 | self.add_note( 828 | pitch=sequence[i], 829 | start_time=self.sequence_length / 830 | 16 * (i + self.note_offset), 831 | duration=self.sequence_length / 16 * self.note_duration, 832 | velocity=int(127 * self.note_velocity), 833 | velocity_deviation=0, 834 | probability=1, 835 | mute=False, 836 | ) 837 | 838 | self.clip.name = self.sequence_names[self.sequence_length] 839 | self.add_handler() 840 | 841 | def set_sequence(self): 842 | notes = [self._parent._transpose_val for i in range(16)] 843 | 844 | if self.sequence_n > 0: 845 | for i in range(0, 16, self.sequence_n): 846 | for j in range(self.sequence_n): 847 | if i + j < len(notes): 848 | notes[i + j] = ( 849 | notes[i + j] + i // self.sequence_n * 850 | self.sequence_up 851 | ) 852 | return notes 853 | 854 | # get_notes_extended( (int)from_pitch, (int)pitch_span, (float)from_time, (float)time_span) -> 855 | # MidiNoteVector : Returns a list of MIDI notes from the given pitch and time range. 856 | # Each note is represented by a Live.Clip.MidiNote object. 857 | # The returned list can be modified freely, but modifications will not be 858 | # reflected in the MIDI clip until apply_note_modifications is called. 859 | 860 | # apply_note_modifications( (MidiNoteVector)arg2) -> 861 | # None : Expects a list of notes as returned from get_notes_extended. 862 | # The content of the list will be used to modify existing notes in the clip, 863 | # based on matching note IDs. This function should be used when modifying 864 | # existing notes, e.g. changing the velocity or start time. 865 | # The function ensures that per-note events attached to the modified notes 866 | # are preserved. This is NOT the case when replacing notes via a combination 867 | # of remove_notes_extended and add_new_notes. The given list can be a subset of 868 | # the notes in the clip, but it must not contain any notes that are not present in the clip. 869 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------