aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-17 04:35:09 +0000
committerDavid Robillard <d@drobilla.net>2010-12-17 04:35:09 +0000
commit5a4c36dd284cf32da44545d89911a86961f205a0 (patch)
treecb9e790cd62f5d47b3f5b7f67ad9260d5f57e921 /src
parent9d10e002f998f560bcaba2aadbc858539f01e6a5 (diff)
downloadmachina-5a4c36dd284cf32da44545d89911a86961f205a0.tar.gz
machina-5a4c36dd284cf32da44545d89911a86961f205a0.tar.bz2
machina-5a4c36dd284cf32da44545d89911a86961f205a0.zip
Show note names as node labels (instead of numbers) (implement ticket #509).
git-svn-id: http://svn.drobilla.net/lad/trunk/machina@2736 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/gui/NodeView.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/gui/NodeView.cpp b/src/gui/NodeView.cpp
index 9e3c2da..7c9bd5f 100644
--- a/src/gui/NodeView.cpp
+++ b/src/gui/NodeView.cpp
@@ -63,20 +63,30 @@ NodeView::handle_click(GdkEventButton* event)
}
+static std::string
+midi_note_name(uint8_t num)
+{
+ static const char* notes[] = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
+
+ const uint8_t octave = num / 12;
+ num -= octave * 12;
+
+ static char str[8];
+ snprintf(str, sizeof(str), "%s%d", notes[num], octave);
+ return str;
+}
+
void
NodeView::show_label(bool show)
{
- char str[4];
-
SharedPtr<Machina::MidiAction> action
= PtrCast<Machina::MidiAction>(_node->enter_action());
if (show) {
if (action && action->event_size() > 1
&& (action->event()[0] & 0xF0) == 0x90) {
- uint8_t note = action->event()[1];
- snprintf(str, 4, "%d", note);
- set_name(str);
+ const uint8_t note_num = action->event()[1];
+ set_name(midi_note_name(note_num));
}
} else {
set_name("");