Skip to content

Commit

Permalink
Set keybord lighting based on the key that is playing
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhadeepJasu committed Aug 21, 2022
1 parent acbf73c commit a0f3211
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 241 deletions.
76 changes: 35 additions & 41 deletions data/Themes/Application.css
Original file line number Diff line number Diff line change
Expand Up @@ -355,95 +355,89 @@
outline: 0;
}


/* Key style */
.common-key > * {
opacity: 0;
}

.common-key > * :active {
background: none;
background-color: alpha(#000, 0);
outline: 0;
}

.common-key > * > * > * > * {
-gtk-icon-transform: rotate(90deg);
}
.white-key-normal {

/* White keys */
.white-key {
background-image:linear-gradient(#585858, #2e2e2e);
border: 2px solid #000;
outline: 0;
}
.white-key-normal > * {

.white-key > * {
padding: 0;
margin: -8px;
margin-top: -42px;
}
.white-key-normal > *:focus {

.white-key > *:focus {
background-color: rgba(0,0,0,0);
}
.white-key-split {
background-image:linear-gradient(#585858, #2e2e2e);
border: 2px solid #000;
}
.white-key-split:active {
background-image:linear-gradient(shade(@accent_color_complimentary, 0.7), shade(@accent_color_complimentary, 0.5));
box-shadow: 0 -12px 8px -8px alpha(@accent_color_complimentary, 0.7), inset 0 -1px 4px @accent_color_complimentary;
}
.white-key-split-active {
background-image:linear-gradient(shade(@accent_color_complimentary, 0.7), shade(@accent_color_complimentary, 0.5));
box-shadow: 0 -12px 8px -8px alpha(@accent_color_complimentary, 0.7), inset 0 -1px 4px @accent_color_complimentary;
}
.white-key-active-auto {

.white-key-auto {
background-image:linear-gradient(shade(@accent_color_complimentary_alternate, 0.7), shade(@accent_color_complimentary_alternate, 0.5));
box-shadow: 0 -12px 8px -8px alpha(@accent_color_complimentary_alternate, 0.65), inset 0 -1px 4px @accent_color_complimentary_alternate;
outline: 0;
}
.white-key-normal:active {
background-image:linear-gradient(shade(@accent_color, 0.7), shade(@accent_color, 0.5));
box-shadow: 0 -12px 8px -8px alpha(@accent_color, 0.65), inset 0 -1px 4px @accent_color;
}

.white-key-active {
background-image:linear-gradient(shade(@accent_color, 0.7), shade(@accent_color, 0.5));
box-shadow: 0 -12px 8px -8px alpha(@accent_color, 0.65), inset 0 -1px 4px @accent_color;
outline: 0;
}
.black-key-normal {

.white-key-chord {
background-image:linear-gradient(shade(@accent_color_complimentary, 0.7), shade(@accent_color_complimentary, 0.5));
box-shadow: 0 -12px 8px -8px alpha(@accent_color_complimentary, 0.7), inset 0 -1px 4px @accent_color_complimentary;
}

/* Black keys */
.black-key {
background-image:linear-gradient(#444, #141414);
border: 2px solid #000;
outline: 0;
}
.black-key-normal > * {

.black-key > * {
padding: 0;
margin: -8px;
margin-top: -42px;
}
.black-key-normal > *:focus {

.black-key > *:focus {
background-color: rgba(0,0,0,0);
}
.black-key-split {
background-image:linear-gradient(#444, #141414);
border: 2px solid #000;
outline: 0;
}
.black-key-split:active {
background-image:linear-gradient(shade(@accent_color_complimentary, 0.7), shade(@accent_color_complimentary, 0.5));
box-shadow: 0 -14px 12px -6px alpha(@accent_color_complimentary, 0.7), inset 0 -1px 4px @accent_color_complimentary;
}
.black-key-split-active {
background-image:linear-gradient(shade(@accent_color_complimentary, 0.7), shade(@accent_color_complimentary, 0.5));
box-shadow: 0 -14px 12px -6px alpha(@accent_color_complimentary, 0.7), inset 0 -1px 4px @accent_color_complimentary;
}
.black-key-active-auto{

.black-key-auto{
background-image:linear-gradient(shade(@accent_color_complimentary_alternate, 0.7), shade(@accent_color_complimentary_alternate, 0.5));
box-shadow: 0 -14px 12px -6px alpha(@accent_color_complimentary_alternate, 0.7), inset 0 -1px 4px @accent_color_complimentary_alternate;
}
.black-key-normal:active{
background-image:linear-gradient(shade(@accent_color, 0.7), shade(@accent_color, 0.5));
box-shadow: 0 -14px 12px -6px alpha(@accent_color, 0.7), inset 0 -1px 4px @accent_color;
}

.black-key-active{
background-image:linear-gradient(shade(@accent_color, 0.7), shade(@accent_color, 0.5));
box-shadow: 0 -14px 12px -6px alpha(@accent_color, 0.7), inset 0 -1px 4px @accent_color;
}

.black-key-chord {
background-image:linear-gradient(shade(@accent_color_complimentary, 0.7), shade(@accent_color_complimentary, 0.5));
box-shadow: 0 -14px 12px -6px alpha(@accent_color_complimentary, 0.7), inset 0 -1px 4px @accent_color_complimentary;
}


.key_label_primary {
background: @accent_color;
border-radius: 50%;
Expand Down
45 changes: 25 additions & 20 deletions src/Core/ArrangerCore.vala
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ namespace Ensembles.Core {
synthesizer.send_notes_realtime (key, is_pressed, velocity);
}
}
Application.main_window.main_keyboard.set_note_on (key, is_pressed);
Application.main_window.main_keyboard.set_note_on (key, is_pressed, Shell.Key.NoteType.NORMAL);
});

arpeggiator.generate_notes.connect ((key, on, velocity) => {
Expand All @@ -199,6 +199,7 @@ namespace Ensembles.Core {
synthesizer.send_notes_realtime (key, on, velocity);
}
});

arpeggiator.halt_notes.connect (synthesizer.halt_realtime);
harmonizer.generate_notes.connect ((key, on, velocity) => {
if (key > Core.CentralBus.get_split_key ()) {
Expand Down Expand Up @@ -238,25 +239,29 @@ namespace Ensembles.Core {
}

public void garbage_collect () {
debug ("Cleaning up Core");
debug ("CLEANUP: Unloading MIDI Input Monitor");
midi_input_host.destroy ();
Thread.usleep (5000);
debug ("CLEANUP: Unloading Metronome and LFO Engine");
metronome_player.unref ();
debug ("CLEANUP: Unloading Style Engine");
style_player.unref ();
if (song_player != null) {
debug ("CLEANUP: Unloading Song Player");
song_player.songplayer_destroy ();
song_player = null;
}
Thread.usleep (5000);
debug ("CLEANUP: Unloading Central Bus");
bus.unref ();
Thread.usleep (5000);
debug ("CLEANUP: Unloading Synthesizer");
synthesizer.synthesizer_deinit ();
Idle.add (() => {
debug ("Cleaning up Core");
debug ("CLEANUP: Unloading MIDI Input Monitor");
midi_input_host.destroy ();
Thread.usleep (5000);
debug ("CLEANUP: Unloading Metronome and LFO Engine");
metronome_player.unref ();
debug ("CLEANUP: Unloading Style Engine");
style_player.unref ();
if (song_player != null) {
debug ("CLEANUP: Unloading Song Player");
song_player.songplayer_destroy ();
song_player = null;
}
Thread.usleep (5000);
debug ("CLEANUP: Unloading Central Bus");
bus.unref ();
Thread.usleep (5000);
debug ("CLEANUP: Unloading Synthesizer");
synthesizer.synthesizer_deinit ();

return false;
});
}

public void load_data () {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/MidiPlayers/SongPlayer/SongPlayer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Ensembles.Core {
current_file_tempo = music_player_load_file (midi_file_path);
player_status_changed (0.0f, current_file_tempo, get_status ());
set_music_note_callback ((note, on) => {
Application.main_window.main_keyboard.set_note_on (note, (on == 144), true);
Application.main_window.main_keyboard.set_note_on (note, (on == 144), Shell.Key.NoteType.AUTOMATION);
});
start_monitoring ();
}
Expand Down
12 changes: 10 additions & 2 deletions src/Core/Synthesizer/Synthesizer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Ensembles.Core {

synthesizer_set_event_callback ((channel, key, velocity, on, c_main, c_type) =>{
// print ("%d, %d, %d, %d, %d, %d\n", channel, key, velocity, on, c_main, c_type);
Application.main_window.main_keyboard.set_note_on (key, (on == 144), true);
Application.main_window.main_keyboard.set_note_on (key, (on == 144), Shell.Key.NoteType.AUTOMATION);
if (Shell.RecorderScreen.sequencer != null &&
Shell.RecorderScreen.sequencer.current_state != MidiRecorder.RecorderState.PLAYING
&& (channel == 17 || channel == 18 || channel == 19)) {
Expand All @@ -42,7 +42,7 @@ namespace Ensembles.Core {
}

public void synthesizer_deinit () {
synthesizer_destruct ();
synthesizer_destruct ();
}

public int set_driver_configuration (string driver_name, double buffer_size) {
Expand All @@ -58,10 +58,18 @@ namespace Ensembles.Core {

public void send_notes_realtime (int key, bool is_pressed, int velocity, int? channel = 17) {
if (input_enabled) {
Application.main_window.main_keyboard.set_note_on (key, is_pressed, Shell.Key.NoteType.NORMAL);

if (!is_pressed)
Application.main_window.main_keyboard.set_note_on (key, false, Shell.Key.NoteType.CHORD);

chord_main = synthesizer_send_notes (key, is_pressed ? 144 : 128, velocity, channel,
Application.settings.get_boolean ("midi-split")
&& Application.arranger_core.midi_input_host.get_connection_status (), out chord_type);

if (chord_main > -6) {
Application.main_window.main_keyboard.set_note_on (key, is_pressed, Shell.Key.NoteType.CHORD);

if (Shell.RecorderScreen.sequencer != null &&
Shell.RecorderScreen.sequencer.current_state != MidiRecorder.RecorderState.PLAYING
&& channel == 17) {
Expand Down
20 changes: 10 additions & 10 deletions src/Core/Synthesizer/synthesizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fluid_synth_t* realtime_render_synth;

// Accompaniment Flags
int accompaniment_mode = 0;
int accompaniment_on = 0;

// Voice Settings
int soundfont_id = 0;
Expand Down Expand Up @@ -229,6 +230,12 @@ synthesizer_set_event_callback (synthesizer_note_event_callback callback)
event_callback = callback;
}

void
synthesizer_set_accomp_enable (int on)
{
accompaniment_on = on;
}

int
handle_events_for_midi_players(fluid_midi_event_t *event, int _is_style_player)
{
Expand Down Expand Up @@ -269,7 +276,7 @@ handle_events_for_midi_players(fluid_midi_event_t *event, int _is_style_player)
}
}
}
if (chan != 9 && get_central_accompaniment_mode () == 0 && type == 144) {
if (chan != 9 && !accompaniment_on && type == 144) {
return 0;
}
if (type == 144)
Expand All @@ -296,7 +303,7 @@ synthesizer_send_notes (int key, int on, int velocity, int channel, u_int8_t mid
{
if (channel >= 17 && channel < 24)
{
if (get_central_accompaniment_mode () > 0)
if (accompaniment_on)
{
if (accompaniment_mode == 0)
{
Expand Down Expand Up @@ -376,7 +383,7 @@ synthesizer_send_notes (int key, int on, int velocity, int channel, u_int8_t mid
{
if (channel == 17)
{
if (get_central_accompaniment_mode () > 0)
if (accompaniment_on)
{
if (accompaniment_mode == 0)
{
Expand Down Expand Up @@ -492,13 +499,6 @@ synthesizer_send_sustain (int on)
synthesizer_change_modulator (17, 66, on > 0 ? 127 : 0);
}


void
synthesizer_set_accomp_enable (int on)
{
set_central_accompaniment_mode (on);
}

float
synthesizer_get_version ()
{
Expand Down
8 changes: 5 additions & 3 deletions src/Shell/Layouts/KeyBed.vala
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ namespace Ensembles.Shell {
}
}

public void set_note_on (int key, bool on, bool? auto = false) {
public void set_note_on (int key, bool on, Key.NoteType note_type) {
if (key > 35 && key < 96) {
octaves[(int)(key / 12) - 3].set_note_on (key % 12, on, auto);
octaves[(int)(key / 12) - 3].set_note_on (key % 12, on, note_type);
}
}

Expand All @@ -149,7 +149,9 @@ namespace Ensembles.Shell {
public void halt_all () {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 11; j++) {
octaves[i].set_note_on (j, false, true);
octaves[i].set_note_on (j, false, Key.NoteType.AUTOMATION);
octaves[i].set_note_on (j, false, Key.NoteType.NORMAL);
octaves[i].set_note_on (j, false, Key.NoteType.CHORD);
}
}
}
Expand Down
Loading

0 comments on commit a0f3211

Please sign in to comment.