Skip to content

Commit

Permalink
Scene: support color sets based on the key of each note
Browse files Browse the repository at this point in the history
As suggested in #100.
  • Loading branch information
kosua20 committed Apr 10, 2021
1 parent edb52a8 commit 2a1af66
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/midi/MIDITrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ void MIDITrack::updateSets(const SetOptions & options){
note.set = int(note.channel);
} else if(options.mode == SetMode::TRACK){
note.set = int(note.track);
} else if(options.mode == SetMode::KEY){
} else if(options.mode == SetMode::SPLIT){
note.set = note.note < options.key ? 0 : 1;
} else if(options.mode == SetMode::KEY){
note.set = noteShift[note.note%12];
} else {
note.set = 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/midi/MIDIUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
enum class SetMode : int {
CHANNEL = 0,
TRACK = 1,
KEY = 2
SPLIT = 2,
KEY = 3
};

struct SetOptions {
Expand Down
8 changes: 5 additions & 3 deletions src/rendering/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,15 +1028,17 @@ void Renderer::showSets(){
if(ImGui::BeginPopup("Note sets options")){
ImGui::Text("Decide how notes should be grouped in multiple sets");
ImGui::Text("(to which you can assign different key/effects colors).");
ImGui::Text("This can be based on the MIDI channel, the track or by");
ImGui::Text("This can be based on the MIDI channel, the track, by key, or by");
ImGui::Text("separating notes that are lower or higher than a given key.");

bool shouldUpdate = false;
shouldUpdate = ImGui::RadioButton("Channel", (int*)(&_state.setOptions.mode), int(SetMode::CHANNEL)) || shouldUpdate;
ImGuiSameLine(120);
ImGuiSameLine(90);
shouldUpdate = ImGui::RadioButton("Track", (int*)(&_state.setOptions.mode), int(SetMode::TRACK)) || shouldUpdate;
ImGuiSameLine(2*120);
ImGuiSameLine(2*90);
shouldUpdate = ImGui::RadioButton("Key", (int*)(&_state.setOptions.mode), int(SetMode::KEY)) || shouldUpdate;
ImGuiSameLine(3*90);
shouldUpdate = ImGui::RadioButton("Split", (int*)(&_state.setOptions.mode), int(SetMode::SPLIT)) || shouldUpdate;
ImGuiSameLine();

ImGuiPushItemWidth(100);
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void State::defineOptions(){
_sharedInfos["colors-per-set"].category = OptionInfos::Category::SETS;

_sharedInfos["sets-mode"] = {"How should notes be grouped into sets", OptionInfos::Type::OTHER};
_sharedInfos["sets-mode"].values = "per-channel: 0, per-track: 1, based on a key separator: 2";
_sharedInfos["sets-mode"].values = "per-channel: 0, per-track: 1, split based on a key separator: 2, per-key: 3";
_sharedInfos["sets-mode"].category = OptionInfos::Category::SETS;

_sharedInfos["sets-separator-key"] = {"If notes are grouped in two sets, defines the key where the split should happen", OptionInfos::Type::KEY, {0.0f, 127.0f}};
Expand Down
5 changes: 4 additions & 1 deletion src/rendering/scene/MIDISceneLive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "../../helpers/ProgramUtilities.h"
#include "../../helpers/ResourcesManager.h"
#include "../../midi/MIDIUtils.h"

#include "MIDISceneLive.h"

Expand Down Expand Up @@ -46,8 +47,10 @@ void MIDISceneLive::updateSet(GPUNote & note, int channel, const SetOptions & op
if(options.mode == SetMode::CHANNEL){
// Restore channel from backup vector.
note.set = float(int(channel) % CHANNELS_COUNT);
} else if(options.mode == SetMode::SPLIT){
note.set = (int(note.note) < options.key ? 0.0f : 1.0f);
} else if(options.mode == SetMode::KEY){
note.set = (note.note < options.key ? 0.0f : 1.0f);
note.set = float(noteShift[int(note.note) % 12]);
} else {
note.set = 0.0f;
}
Expand Down

0 comments on commit 2a1af66

Please sign in to comment.