Skip to content

Commit

Permalink
Many note mode tweaks for usability and implementation of feature req…
Browse files Browse the repository at this point in the history
…uest for highlighting notes in scale
  • Loading branch information
codicusmaximus committed Jul 8, 2017
1 parent c9538e0 commit c576d32
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 34 deletions.
11 changes: 11 additions & 0 deletions include/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
extern const uint8_t root_note_color[3];
extern const uint8_t white_note_color[3];
extern const uint8_t black_note_color[3];
extern const uint8_t invalid_note_color[3];
extern const uint8_t c_note_color[3];
extern const uint8_t no_note_color[3];

extern const uint8_t layout_octave_color[3];
extern const uint8_t layout_transpose_color[3];

extern const uint8_t white_key_color[3];
extern const uint8_t black_key_color[3];
extern const uint8_t slider_color[3];
extern const uint8_t off_color[3];
extern const uint8_t on_color[3];

extern const uint8_t note_octave_up_colors[10][3];
extern const uint8_t note_octave_down_colors[10][3];
extern const uint8_t note_transpose_up_colors[12][3];
extern const uint8_t note_transpose_down_colors[12][3];

extern const uint8_t sequence_colors[8][3];
extern const uint8_t number_colors[4][3];
extern const uint8_t drum_colors[4][3];
Expand Down
1 change: 1 addition & 0 deletions include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern Note* lp_note_storage;
extern Scale lp_scale;
extern Voices lp_voices;
extern PadNotes lp_pad_notes;
extern PadNotes lp_pad_highlights;
extern Sequencer lp_sequencer;

// Setup UI elements
Expand Down
1 change: 1 addition & 0 deletions include/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define VELOCITY_CHECKBOX_POS (41)
#define MOD_WHEEL_CHECKBOX_POS (43)
#define MOD_CC_CHECKBOX_POS (53)
#define NOTE_HIGHLIGHT_ONLY_POS (28)
#define DRUM_CHECKBOX_POS (45)
#define MULTICHANNEL_CHECKBOX_POS (55)
#define CONTROL_CHECKBOX_POS (81)
Expand Down
4 changes: 2 additions & 2 deletions include/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ typedef struct
void keyboard_init(Keyboard* k, Layout* l);

/// Toggles a note on or off and updates the layout and scale to match.
uint8_t keyboard_handle_press(Keyboard* k, uint8_t index, uint8_t value);
uint8_t keyboard_handle_press(Keyboard* k, uint8_t index, uint8_t value, uint8_t is_highlight_press);

/// Draws the keyboard to the grid.
void keyboard_draw(Keyboard* k);
void keyboard_draw(Keyboard* k, uint8_t draw_highlighted);

/// When a change is made to the layout or scale, this function updates the
/// keyboard to reflect the current state.
Expand Down
7 changes: 7 additions & 0 deletions include/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "voices.h"
#include "util.h"

#define LAYOUT_DEFAULT_OCTAVE 3

/// The bits where row offset lives. Excludes the drum flag bit, so that
/// the drums state doesn't get trashed when you use the row offset slider.
#define ROW_OFFSET_MASK (0x7F)
Expand All @@ -26,6 +28,9 @@ typedef enum
/// calculating every time a pad is pressed.
typedef int8_t PadNotes[GRID_SIZE][GRID_SIZE];

/// Cache of which pads are highlighted for note mode
typedef int8_t PadHighlights[GRID_SIZE];

/// Represents a layout of a scale on a grid. Determines which note and octave
/// to start from, and the distance in scale steps between rows of the grid.
typedef struct
Expand Down Expand Up @@ -64,6 +69,8 @@ void layout_set_drums(Layout* l);

/// Toggles the note in the scale, and updates the layout.
void layout_toggle_note(Layout* l, uint8_t note);
/// Toggles the note highlight
void layout_toggle_highlight(Layout* l, uint8_t note_highlight);

/// Draws the layout onto the grid.
void layout_draw(Layout* l);
Expand Down
12 changes: 12 additions & 0 deletions include/scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ typedef struct
/// note) is enabled. [0] (the root note) is always on.
uint16_t notes;

/// Bitfield indicating whether the nth note is lighted or not
/// which applies if the highlight setting is turned on
/// Otherwise, white keys are lighted and black keys are dark
uint16_t notes_highlighted;

/// Array of ints indicating how many half steps the nth scale note is
/// offset from the root note (only the first num_notes entries are set)
int8_t offsets[NUM_NOTES];
Expand All @@ -28,11 +33,18 @@ void scale_init(Scale* s);
/// root note) is contained in the scale.
uint8_t scale_contains_note(Scale* s, uint8_t note);

/// Returns true or false depending on whether then nth note (counted from the
/// root note) is contained in the scale's highlight list
uint8_t scale_contains_highlight(Scale* s, uint8_t note);

/// Sets all the notes of the scale at once.
void scale_set_notes(Scale* s, uint16_t notes);

/// Toggles the nth note in the scale. Automatically updates num_notes and
/// offsets.
void scale_toggle_note(Scale* s, uint8_t note);

/// Toggles the nth note's highlight
void scale_toggle_highlight(Scale* s, uint8_t note);

#endif
3 changes: 2 additions & 1 deletion include/sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ typedef enum
SEQ_DRUM_MULTICHANNEL = 1 << 11, // Send each note on its own channel
SEQ_FULL_VELOCITY = 1 << 12, // Always send notes at full velocity
SEQ_MOD_WHEEL = 1 << 13, // Show the mod wheel in notes mode
SEQ_MOD_CC = 1 << 14 // Send CC from mod wheel instead of aftertouch
SEQ_MOD_CC = 1 << 14, // Send CC from mod wheel instead of aftertouch
NOTE_HIGHLIGHT_ONLY = 1 << 15 // Always show all notes and only highlight the ones in the scale
} SequenceFlags;

#define SEQ_QUEUED_OFFSET (4)
Expand Down
Binary file modified resources/subsequencely.syx
Binary file not shown.
66 changes: 63 additions & 3 deletions src/colors.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,78 @@
#include "app.h"
#include "colors.h"

const uint8_t root_note_color[3] = {0x0F, 0x04, 0x04};
const uint8_t white_note_color[3] = {0x02, 0x02, 0x06};
const uint8_t black_note_color[3] = {0x00, 0x00, 0x00};
const uint8_t root_note_color[3] = {0x78, 0x20, 0x20};
const uint8_t white_note_color[3] = {0x10, 0x10, 0x30};
const uint8_t black_note_color[3] = {0x04, 0x04, 0x04};
const uint8_t invalid_note_color[3] = {0x3F, 0x00, 0x00};
const uint8_t c_note_color[3] = {0x02, 0x06, 0x02};
const uint8_t no_note_color[3] = {0x0F, 0x00, 0x00};

const uint8_t layout_octave_color[3] = {0x00, 0x00, 0xFF};
const uint8_t layout_transpose_color[3] = {0x00, 0xFF, 0x00};

const uint8_t white_key_color[3] = {0x0F, 0x2F, 0x7F};
const uint8_t black_key_color[3] = {0x3F, 0x00, 0x17};
const uint8_t slider_color[3] = {0x07, 0x7F, 0x0F};
const uint8_t off_color[3] = {0x00, 0x00, 0x00};
const uint8_t on_color[3] = {0xFF, 0xFF, 0xFF};

const uint8_t note_octave_up_colors[10][3] = {
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x02},
{0x00, 0x00, 0x08},
{0x00, 0x00, 0x20}, // Default Octave
{0x00, 0x00, 0x28},
{0x00, 0x00, 0x30},
{0x00, 0x00, 0x3F},
{0x10, 0x00, 0x3F},
{0x3F, 0x00, 0x20},
{0x3F, 0x00, 0x00}
};

const uint8_t note_octave_down_colors[10][3] = {
{0x00, 0x00, 0x3F},
{0x00, 0x00, 0x30},
{0x00, 0x00, 0x28},
{0x00, 0x00, 0x20}, // Default Octave
{0x00, 0x00, 0x08},
{0x00, 0x00, 0x02},
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00}
};

const uint8_t note_transpose_up_colors[12][3] = {
{0x00, 0x00, 0x00}, // 0 (default / no transposition)
{0x00, 0x04, 0x00}, // +1
{0x00, 0x20, 0x00}, // +2
{0x00, 0x3F, 0x00}, // +3
{0x0F, 0x37, 0x00}, // +4
{0x1F, 0x2F, 0x00}, // +5
{0x2F, 0x27, 0x00}, //+-6
{0x00, 0x00, 0x00}, // -5
{0x00, 0x00, 0x00}, // -4
{0x00, 0x00, 0x00}, // -3
{0x00, 0x00, 0x00}, // -2
{0x00, 0x00, 0x00} // -1
};

const uint8_t note_transpose_down_colors[12][3] = {
{0x00, 0x00, 0x00}, // 0 (default / no transposition)
{0x00, 0x00, 0x00}, // +1
{0x00, 0x00, 0x00}, // +2
{0x00, 0x00, 0x00}, // +3
{0x00, 0x00, 0x00}, // +4
{0x00, 0x00, 0x00}, // +5
{0x2F, 0x27, 0x00}, //+-6
{0x1F, 0x2F, 0x00}, // -5
{0x0F, 0x37, 0x00}, // -4
{0x00, 0x3F, 0x00}, // -3
{0x00, 0x20, 0x00}, // -2
{0x00, 0x04, 0x00} // -1
};

const uint8_t sequence_colors[8][3] = {
{0x7F, 0x00, 0x00},
{0x3F, 0x0F, 0x00},
Expand Down
4 changes: 2 additions & 2 deletions src/grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void grid_update_cache(Sequencer* sr, int8_t translation)
}
else if (translation == -1)
{
uint8_t scale_deg = (s->y + GRID_SIZE) % lp_scale.num_notes;
//uint8_t scale_deg = (s->y + GRID_SIZE) % lp_scale.num_notes;
for (uint8_t i = GRID_SIZE; i > 0; i--)
{
note_numbers[i] = note_numbers[i - 1];
Expand Down Expand Up @@ -63,7 +63,7 @@ void grid_draw(Sequencer* sr)
for (uint8_t x = 0; x < GRID_SIZE; x++)
{
uint8_t seq_x = grid_to_sequence_x(s, x);
Note* n;
Note* n = 0;
uint8_t y;

for (uint8_t n_i = 0; n_i < zoom; n_i++)
Expand Down
19 changes: 14 additions & 5 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ uint8_t keyboard_index_is_key(Keyboard* k, uint8_t index)
return k->index_to_note[index - FIRST_KEYBOARD_PAD] != -1;
}

uint8_t keyboard_handle_press(Keyboard* k, uint8_t index, uint8_t value)
uint8_t keyboard_handle_press(Keyboard* k, uint8_t index, uint8_t value, uint8_t is_highlight_press)
{
if (value == 0 || !keyboard_index_is_key(k, index))
{
Expand All @@ -68,12 +68,18 @@ uint8_t keyboard_handle_press(Keyboard* k, uint8_t index, uint8_t value)
uint8_t deg = (k->index_to_note[index - FIRST_KEYBOARD_PAD]
- k->layout->root_note
+ NUM_NOTES) % NUM_NOTES;
layout_toggle_note(k->layout, deg);

if (is_highlight_press)
{
layout_toggle_highlight(k->layout, deg);
}
else
{
layout_toggle_note(k->layout, deg);
}
return 1;
}

void keyboard_draw(Keyboard* k)
void keyboard_draw(Keyboard* k, uint8_t draw_highlighted)
{
const uint8_t* color = white_key_color;

Expand All @@ -99,7 +105,10 @@ void keyboard_draw(Keyboard* k)
}

int8_t deg = (note + NUM_NOTES - k->layout->root_note) % NUM_NOTES;
uint8_t is_in_scale = scale_contains_note(&lp_scale, deg);
if (draw_highlighted && !scale_contains_note(&lp_scale, deg)) {
color = invalid_note_color;
}
uint8_t is_in_scale = draw_highlighted ? scale_contains_highlight(&lp_scale, deg) : scale_contains_note(&lp_scale, deg);
uint8_t dimness = !is_in_scale * 4;
plot_pad_dim(i + FIRST_KEYBOARD_PAD, color, dimness);
}
Expand Down
Loading

0 comments on commit c576d32

Please sign in to comment.