Skip to content

Commit

Permalink
save scale in clip. customisable user modes
Browse files Browse the repository at this point in the history
- save scale in clip in stepseq and instrument mode (off by default,
check Settings.py)
- customisable user modes (in Settings.py)
- clean up TrackController
  • Loading branch information
hdavid committed Apr 3, 2015
1 parent 5d81380 commit 9ceff5a
Show file tree
Hide file tree
Showing 8 changed files with 404 additions and 182 deletions.
56 changes: 50 additions & 6 deletions InstrumentControllerComponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ScaleComponent import * # noqa
from StepSequencerComponent import StepSequencerComponent
from consts import * # noqa
import Settings

class InstrumentControllerComponent(CompoundComponent):

Expand Down Expand Up @@ -67,12 +68,17 @@ def set_enabled(self, enabled):
if not enabled:
self._parent._parent.release_controlled_track()
else:
self._parent._parent.set_controlled_track(self.song().view.selected_track)
self._parent._parent.set_controlled_track(self._track_controller.selected_track)

if self._track_controller != None:
self._track_controller._do_implicit_arm(enabled)
self._track_controller.set_enabled(enabled)

if enabled:
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "track":
self._scales.from_object(self._track_controller.selected_track)
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "clip":
self._scales.from_object(self._track_controller.selected_clip)
self._update_OSD()

def _set_feedback_velocity(self):
Expand Down Expand Up @@ -116,14 +122,19 @@ def _scales_toggle(self, value, sender):
if self.is_enabled():
self._scales_toggle_button.set_on_off_values(AMBER_FULL, AMBER_THIRD)
if (value is not 0):
self._osd_mode_backup = self._osd.mode
self._scales.set_enabled(True)
self._osd_mode_backup = self._osd.mode
self._osd.mode = self._osd_mode_backup + ' - Scale'
self._scales_toggle_button.turn_on()
self._scales.update()
else:
self._scales_toggle_button.turn_off()
self._scales.set_enabled(False)
#TODO: save scale setting in track or clip. detect if changed
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "track":
self._scales.update_object_name(self._track_controller.selected_track)
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "clip":
self._scales.update_object_name(self._track_controller.selected_clip)
self._osd.mode = self._osd_mode_backup
self.update()

Expand Down Expand Up @@ -217,12 +228,23 @@ def _matrix_value_quickscale(self, value, x, y, is_momentary): # matrix buttons
if root != -1:
self._scales.set_selected_modus(selected_modus)
self._scales.set_key(root)
#TODO: save scale in clip or track name
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "track":
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "track":
self._scales.update_object_name(self._track_controller.selected_track)
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "clip":
self._scales.update_object_name(self._track_controller.selected_clip)
self.update()

else:
if(y == 0):
if x < 7 and self._quick_scales[x] != -1:
self._scales.set_selected_modus(self._quick_scales[x])
#TODO: save scale in clip or track name
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "track":
self._scales.update_object_name(self._track_controller.selected_track)
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "clip":
self._scales.update_object_name(self._track_controller.selected_clip)
self._parent._parent.show_message("mode : "+str(self._scales._modus_names[self._scales._selected_modus]))
self.update()
if x == 7:
Expand All @@ -235,6 +257,11 @@ def _matrix_value_quickscale(self, value, x, y, is_momentary): # matrix buttons
if(y == 1):
if x < 8 and self._quick_scales[x + 7] != -1:
self._scales.set_selected_modus(self._quick_scales[x + 7])
#TODO: save scale in clip or track name
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "track":
self._scales.update_object_name(self._track_controller.selected_track)
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "clip":
self._scales.update_object_name(self._track_controller.selected_clip)
self._parent._parent.show_message("mode : "+str(self._scales._modus_names[self._scales._selected_modus]))
self.update()

Expand Down Expand Up @@ -295,8 +322,8 @@ def _update_OSD(self):
self._osd.attributes[7] = " "
self._osd.attribute_names[7] = " "

if self.song().view.selected_track != None:
self._osd.info[0] = "track : " + self.song().view.selected_track.name
if self._track_controller.selected_track != None:
self._osd.info[0] = "track : " + self._track_controller.selected_track.name
else:
self._osd.info[0] = " "

Expand All @@ -322,11 +349,28 @@ def on_selected_track_changed(self):
self._scales.set_drumrack(True)
else:
self._scales.set_drumrack(False)

#load scale settings from track
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "track":
self._scales.from_object(self._track_controller.selected_track)
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "clip":
self._scales.from_object(self._track_controller.selected_clip)
# must be delayed.... self._scales.update_object_name(track)

self.update()

def on_selected_scene_changed(self):
if self._track_controller._implicit_arm:
#load scale settings from track
if Settings.INSTRUMENT__SAVE_SCALE != None and Settings.INSTRUMENT__SAVE_SCALE == "clip":
self._scales.from_object(self._track_controller.selected_clip)
# must be delayed.... self._scales.update_object_name(track)

self.update()

def _get_drumrack_device(self):
if self.song().view.selected_track != None:
track = self.song().view.selected_track
if self._track_controller.selected_track != None:
track = self._track_controller.selected_track
if(track.devices != None and len(track.devices) > 0):
#device = track.devices[0]
device = self.find_drum_group_device(track)
Expand Down
135 changes: 81 additions & 54 deletions MainSelectorComponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,60 +214,21 @@ def update(self):
self._update_control_channels()
self._mode_index = 0

elif self._main_mode_index == 1:
self._setup_session(not as_active, not as_enabled)
self._setup_step_sequencer(not as_active)
self._setup_step_sequencer2(not as_active)
self._setup_mixer(not as_active)
if self._sub_mode_index[self._main_mode_index] == 0:
# instrument controller
self._setup_device_controller(not as_active)
self._update_control_channels()
self._setup_instrument_controller(as_active)
self._mode_index = 4
elif self._sub_mode_index[self._main_mode_index] == 1:
# device controller
self._setup_instrument_controller(not as_active)
self._setup_device_controller(as_active)
self._update_control_channels()
self._mode_index = 5
else:
# plain user mode 1
self._setup_device_controller(not as_active)
self._setup_instrument_controller(not as_active)
self._setup_user_mode(True, True, False, True)
self._update_control_channels()
self._mode_index = 1
self._osd.clear()
self._osd.mode = "User 1"
self._osd.update()

elif self._main_mode_index == 2:
self._setup_session(not as_active, not as_enabled)
self._setup_instrument_controller(not as_active)
self._setup_device_controller(not as_active)
self._setup_mixer(not as_active)
if self._sub_mode_index[self._main_mode_index] == 0:
# stepseq
self._setup_step_sequencer2(not as_active)
self._setup_step_sequencer(as_active)
self._mode_index = 6
elif self._sub_mode_index[self._main_mode_index] == 1:
# melodic step seq
self._setup_step_sequencer(not as_active)
self._setup_step_sequencer2(as_active)
self._mode_index = 7
else:
# plain user mode 2
self._setup_step_sequencer(not as_active)
self._setup_step_sequencer2(not as_active)
self._setup_user_mode(False, False, False, False)
self._mode_index = 2
self._osd.clear()
self._osd.mode = "User 2"
self._osd.update()

self._update_control_channels()
elif self._main_mode_index == 1 or self._main_mode_index == 2:
self._setup_usermode(Settings.USER_MODES[ (self._main_mode_index-1) * 3 + self._sub_mode_index[self._main_mode_index] ] )
#if self._sub_mode_index[self._main_mode_index] == 0:
# self._setup_usermode(Settings.USER_MODES[0])
#elif self._sub_mode_index[self._main_mode_index] == 1:
# self._setup_usermode(Settings.USER_MODES[1])
#else:
# self._setup_usermode(Settings.USER_MODES[2])
#elif self._main_mode_index == 2:
# if self._sub_mode_index[self._main_mode_index] == 0:
# self._setup_usermode(Settings.USER_MODES[3])
# elif self._sub_mode_index[self._main_mode_index] == 1:
# self._setup_usermode(Setting.USER_MODES[4])
# else:
# self._setup_usermode(Settings.USER_MODES[5])

elif self._main_mode_index == 3:
# mixer
Expand All @@ -289,6 +250,72 @@ def update(self):
#for line in traceback.format_stack():
# self.log_message(line.strip())

def _setup_usermode(self, mode):
as_active = True
as_enabled = True
if mode == "instrument":
self._setup_session(not as_active, not as_enabled)
self._setup_step_sequencer(not as_active)
self._setup_step_sequencer2(not as_active)
self._setup_mixer(not as_active)
self._setup_device_controller(not as_active)
self._update_control_channels()
self._setup_instrument_controller(as_active)
self._mode_index = 4
elif mode == "melodic stepseq":
self._setup_session(not as_active, not as_enabled)
self._setup_instrument_controller(not as_active)
self._setup_device_controller(not as_active)
self._setup_mixer(not as_active)
self._setup_step_sequencer(not as_active)
self._setup_step_sequencer2(as_active)
self._update_control_channels()
self._mode_index = 7
elif mode == "user 1":
self._setup_session(not as_active, not as_enabled)
self._setup_step_sequencer(not as_active)
self._setup_step_sequencer2(not as_active)
self._setup_mixer(not as_active)
self._setup_device_controller(not as_active)
self._setup_instrument_controller(not as_active)
self._setup_user_mode(True, True, False, True)
self._update_control_channels()
self._mode_index = 1
self._osd.clear()
self._osd.mode = "User 1"
self._osd.update()
elif mode == "drum stepseq":
self._setup_session(not as_active, not as_enabled)
self._setup_instrument_controller(not as_active)
self._setup_device_controller(not as_active)
self._setup_mixer(not as_active)
self._setup_step_sequencer2(not as_active)
self._setup_step_sequencer(as_active)
self._update_control_channels()
self._mode_index = 6
elif mode == "device":
self._setup_session(not as_active, not as_enabled)
self._setup_step_sequencer(not as_active)
self._setup_step_sequencer2(not as_active)
self._setup_mixer(not as_active)
self._setup_instrument_controller(not as_active)
self._setup_device_controller(as_active)
self._update_control_channels()
self._mode_index = 5
elif mode == "user 2":
self._setup_session(not as_active, not as_enabled)
self._setup_instrument_controller(not as_active)
self._setup_device_controller(not as_active)
self._setup_mixer(not as_active)
self._setup_step_sequencer(not as_active)
self._setup_step_sequencer2(not as_active)
self._setup_user_mode(False, False, False, False)
self._update_control_channels()
self._mode_index = 2
self._osd.clear()
self._osd.mode = "User 2"
self._osd.update()

def _setup_session(self, as_active, as_enabled):
assert isinstance(as_active, type(False))
for button in self._nav_buttons:
Expand Down
95 changes: 94 additions & 1 deletion ScaleComponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from _Framework.ControlSurfaceComponent import ControlSurfaceComponent
from consts import * # noqa
import string
import traceback

class InstrumentPresetsComponent():

Expand Down Expand Up @@ -182,7 +184,97 @@ def get_scale_note_color(self):

def get_scale_highlight_color(self):
return self.scale_highlight_color


def from_object(self, obj = None , obj2 = None):
datas = None

if obj != None:
data = obj.name
d = string.split(data,'^')
if len(d)==2:
d = string.split(d[1],",")
if len(d)==4:
datas = d

if obj2 != None and datas == None:
data = obj2.name
d = string.split(data,'^')
if len(d)==2:
d = string.split(d[1],",")
if len(d)==4:
datas = d

if datas !=None and len(datas)==4:
try:
self._selected_key = int(datas[0])
except ValueError:
self._selected_key = 0
try:
self._selected_modus = int(datas[1])
except ValueError:
self._selected_modus = 0
try:
self._octave_index = int(datas[2])
except ValueError:
self._octave_index = 3

mode = datas[3]
if mode=="d":
self._is_drumrack = True
#self._is_chromatic = True
#self._is_diatonic = False
#self._is_diatonic_ns = False
#self._is_chromatic_gtr = False
else:
self._is_drumrack = False
if mode=="g":
self._is_chromatic_gtr = True
self._is_diatonic = False
self._is_diatonic_ns = False
self._is_chromatic = False
elif mode=="c":
self._is_chromatic = True
self._is_diatonic = False
self._is_diatonic_ns = False
self._is_chromatic_gtr = False
elif mode=="n":
self._is_diatonic_ns = True
self._is_diatonic = False
self._is_chromatic_gtr = False
self._is_chromatic = False
else:
self._is_diatonic = True
self._is_diatonic_ns = False
self._is_chromatic_gtr = False
self._is_chromatic = False

def get_string(self):
mode = "c";
if(self._is_drumrack):
mode="d"
else:
mode="a"
if(self._is_chromatic):
mode="c"
if(self._is_chromatic_gtr):
mode="g"
if(self._is_diatonic):
mode="a"
if(self._is_diatonic_ns):
mode="n"
return(str(self._selected_key)+","+str(self._selected_modus)+","+str(self._octave_index)+","+mode)

def update_object_name(self, obj , obj2 = None):
scale_string = self.get_string()
if obj != None:
name = obj.name
data = string.split(name," ^")
obj.name = data[0] + " ^" + scale_string
if obj2 != None:
name = obj2.name
data = string.split(name," ^")
obj2.name = data[0] + " ^" + scale_string

def set_diatonic(self, interval=-1):
self._is_drumrack = False
self._is_chromatic = False
Expand Down Expand Up @@ -352,6 +444,7 @@ def _matrix_value(self, value, x, y, is_momentary): # matrix buttons listener


self.update()
#self._parent._parent._parent.show_message("mode : "+self.get_string())

def tuple_idx(self, tuple, obj):
for i in xrange(0, len(tuple)):
Expand Down
Loading

0 comments on commit 9ceff5a

Please sign in to comment.