Skip to content

Commit

Permalink
improved support for launchpad95
Browse files Browse the repository at this point in the history
  • Loading branch information
hdavid committed Dec 11, 2013
1 parent e09ccd6 commit 5b10912
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
8 changes: 5 additions & 3 deletions InstrumentControllerComponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def __init__(self, matrix, side_buttons, top_buttons, parent):
self._remaining_buttons = []
self._track_controller = None
self.base_channel = 11

self._normal_feedback_velocity = AMBER_FULL
self._recordind_feedback_velocity = RED_FULL

self._drum_group_device = None
self._octave_up_button = None
self._octave_down_button = None
Expand Down Expand Up @@ -76,9 +78,9 @@ def set_enabled(self, enabled):

def _set_feedback_velocity(self):
if self.song().session_record:
self._parent._parent._c_instance.set_feedback_velocity(RED_FULL)
self._parent._parent._c_instance.set_feedback_velocity(self._recordind_feedback_velocity)
else:
self._parent._parent._c_instance.set_feedback_velocity(AMBER_FULL)
self._parent._parent._c_instance.set_feedback_velocity(self._normal_feedback_velocity)

@subject_slot('session_record')
def _on_session_record_changed(self):
Expand Down
73 changes: 36 additions & 37 deletions NoteEditorComponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@
from _Framework.ButtonMatrixElement import ButtonMatrixElement
import time

#metronome
DISPLAY_METRONOME = True
METRONOME_COLOUR = AMBER_FULL

#Velocity colour map. this must remain of lengh 3.
VELOCITY_MAP = [70,90,110]
VELOCITY_COLOR_MAP = [GREEN_THIRD,GREEN_HALF,GREEN_FULL]

LONG_BUTTON_PRESS=0.500

# self._clip_notes = self._clip.get_notes(time_start, self._note_index, time_length, 1)
# self._sequencer_clip.remove_notes(time, self._note_index, length, 1)
# note = (pitch, time, self._get_step_length(), velocity, mute)
# self._sequencer_clip.set_notes((note,))

class NoteEditorComponent(ControlSurfaceComponent):

def __init__(self, parent, matrix):
ControlSurfaceComponent.__init__(self)
self.set_enabled(False)
self._parent = parent


#metronome
self.display_metronome = True
self.metronome_color = AMBER_FULL

#Velocity colour map. this must remain of lengh 3.
self.velocity_map = [70,90,110]
self.velocity_color_map = [GREEN_THIRD,GREEN_HALF,GREEN_FULL]
#other colors
self.muted_note_color = RED_THIRD
self.playing_note_color = RED_FULL

self.long_button_press=0.500

#buttons
self._matrix = None
self._mute_shift_button = None
Expand Down Expand Up @@ -64,7 +63,7 @@ def __init__(self, parent, matrix):

#velocity
self._velocity_index = 2
self._velocity = VELOCITY_MAP[self._velocity_index]
self._velocity = self.velocity_map[self._velocity_index]
self._is_velocity_shifted = False
self._velocity_notes_pressed=0
self._velocity_last_press=time.time()
Expand Down Expand Up @@ -216,9 +215,9 @@ def _update_matrix(self): #step grid LEDs are updated here
play_y_position = int(play_position / self.quantization / self.width)%self.height

# add play positition in amber
if(DISPLAY_METRONOME):
if(self.display_metronome):
if self._clip.is_playing and self.song().is_playing:
self._grid_back_buffer[play_x_position][play_y_position] = AMBER_THIRD
self._grid_back_buffer[play_x_position][play_y_position] = self.metronome_color

if(self._display_page):
self._display_selected_page()
Expand Down Expand Up @@ -265,22 +264,22 @@ def _update_matrix(self): #step grid LEDs are updated here

if note_grid_x_position>=0:
#compute colors
highlight_color = RED_FULL
for index in range(len(VELOCITY_MAP)):
if note_velocity>=VELOCITY_MAP[index]:
highlight_color=RED_FULL
velocity_color = GREEN_THIRD
for index in range(len(VELOCITY_MAP)):
if note_velocity>=VELOCITY_MAP[index]:
velocity_color=VELOCITY_COLOR_MAP[index]
highlight_color = self.playing_note_color
for index in range(len(self.velocity_map)):
if note_velocity>=self.velocity_map[index]:
highlight_color=self.playing_note_color
velocity_color = self.velocity_map[0]
for index in range(len(self.velocity_map)):
if note_velocity>=self.velocity_map[index]:
velocity_color=self.velocity_color_map[index]
#highligh playing notes in red. even if they are from other pages.
if not note_muted and note_page == play_page and play_x_position==note_grid_x_position and (play_y_position==note_grid_y_position and not self.is_multinote or self.is_multinote and note_grid_y_offset==play_row) and self.song().is_playing and self._clip.is_playing:
self._grid_back_buffer[note_grid_x_position][note_grid_y_position]=RED_FULL;
self._grid_back_buffer[note_grid_x_position][note_grid_y_position]=self.playing_note_color
elif note_page == self._page: #if note is in current page, then update grid
#do not erase current note highlight
if self._grid_back_buffer[note_grid_x_position][note_grid_y_position]!=highlight_color:
if self._grid_back_buffer[note_grid_x_position][note_grid_y_position]!=self.playing_note_color:
if note_muted:
self._grid_back_buffer[note_grid_x_position][note_grid_y_position]=RED_THIRD
self._grid_back_buffer[note_grid_x_position][note_grid_y_position]=self.muted_note_color
else:
self._grid_back_buffer[note_grid_x_position][note_grid_y_position]=velocity_color

Expand Down Expand Up @@ -357,10 +356,10 @@ def _matrix_value_message(self, values): #value, x, y, is_momentary): #matrix bu
if self._is_velocity_shifted:
#update velocity of the note
new_velocity_index=0
for index in range(len(VELOCITY_MAP)):
if note[3]>=VELOCITY_MAP[index]:
new_velocity_index=(index+1)%len(VELOCITY_MAP)
note_cache.append([note[0], note[1], note[2], VELOCITY_MAP[new_velocity_index], note[4]])
for index in range(len(self.velocity_map)):
if note[3]>=self.velocity_map[index]:
new_velocity_index=(index+1)%len(self.velocity_map)
note_cache.append([note[0], note[1], note[2], self.velocity_map[new_velocity_index], note[4]])
elif not self._is_mute_shifted:
note_cache.remove(note)
else:
Expand All @@ -386,7 +385,7 @@ def _update_velocity_button(self):
self._velocity_button.set_on_off_values(GREEN_FULL,GREEN_THIRD)
self._velocity_button.turn_on()
else:
self._velocity_button.set_on_off_values(VELOCITY_COLOR_MAP[self._velocity_index],LED_OFF)
self._velocity_button.set_on_off_values(self.velocity_color_map[self._velocity_index],LED_OFF)
self._velocity_button.turn_on()
else:
self._velocity_button.set_on_off_values(LED_OFF,LED_OFF)
Expand All @@ -409,10 +408,10 @@ def _velocity_value(self, value, sender):
if self.is_enabled():
if ((value is 0) or (not sender.is_momentary())):
#button released
if self._velocity_notes_pressed==0 and time.time()-self._velocity_last_press<LONG_BUTTON_PRESS:
if self._velocity_notes_pressed==0 and time.time()-self._velocity_last_press<self.long_button_press:
#cycle thru velocities
self._velocity_index = (len(VELOCITY_MAP)+self._velocity_index+1)%len(VELOCITY_MAP)
self._velocity = VELOCITY_MAP[self._velocity_index]
self._velocity_index = (len(self.velocity_map)+self._velocity_index+1)%len(self.velocity_map)
self._velocity = self.velocity_map[self._velocity_index]
self._is_velocity_shifted = False
self._update_velocity_button()
if ((value is not 0) or (not sender.is_momentary())):
Expand Down

0 comments on commit 5b10912

Please sign in to comment.