From 5a4c36dd284cf32da44545d89911a86961f205a0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 17 Dec 2010 04:35:09 +0000 Subject: 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 --- src/gui/NodeView.cpp | 20 +++++++++++++++----- 1 file 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 action = PtrCast(_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(""); -- cgit v1.2.1