From 44d6d5f4270c6fb8db5d51745c03bb47b79289fe Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 22 Jun 2017 00:23:17 -0400 Subject: [PATCH] Highlight MIDI channel buttons --- src/NoteTrack.cpp | 13 ++++++++++--- src/NoteTrack.h | 3 ++- src/TrackPanel.cpp | 5 ++++- .../notetrack/ui/NoteTrackButtonHandle.cpp | 13 ++++++++++++- .../notetrack/ui/NoteTrackButtonHandle.h | 4 ++++ 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/NoteTrack.cpp b/src/NoteTrack.cpp index dddd76e99..4ccbd5987 100644 --- a/src/NoteTrack.cpp +++ b/src/NoteTrack.cpp @@ -251,7 +251,7 @@ void NoteTrack::WarpAndTransposeNotes(double t0, double t1, // Draws the midi channel toggle buttons within the given rect. // The rect should be evenly divisible by 4 on both axis. void NoteTrack::DrawLabelControls -( const NoteTrack *pTrack, wxDC & dc, const wxRect &rect ) +( const NoteTrack *pTrack, wxDC & dc, const wxRect &rect, int highlightedChannel ) { wxASSERT_MSG(rect.width % 4 == 0, "Midi channel control rect width must be divisible by 4"); wxASSERT_MSG(rect.height % 4 == 0, "Midi channel control rect height must be divisible by 4"); @@ -273,7 +273,11 @@ void NoteTrack::DrawLabelControls bool visible = pTrack ? pTrack->IsVisibleChan(chanName - 1) : true; if (visible) { - AColor::MIDIChannel(&dc, chanName); + // highlightedChannel counts 0 based + if ( chanName == highlightedChannel + 1 ) + AColor::LightMIDIChannel(&dc, chanName); + else + AColor::MIDIChannel(&dc, chanName); dc.DrawRectangle(box); // two choices: channel is enabled (to see and play) when button is in // "up" position (original Audacity style) or in "down" position @@ -299,7 +303,10 @@ void NoteTrack::DrawLabelControls box.x, box.y + box.height - 1, box.x + box.width - 1, box.y + box.height - 1); } else { - AColor::MIDIChannel(&dc, 0); + if ( chanName == highlightedChannel + 1 ) + AColor::LightMIDIChannel(&dc, chanName); + else + AColor::MIDIChannel(&dc, 0); dc.DrawRectangle(box); #if CHANNEL_ON_IS_DOWN AColor::LightMIDIChannel(&dc, 0); diff --git a/src/NoteTrack.h b/src/NoteTrack.h index 7c705e56c..03b78c51b 100644 --- a/src/NoteTrack.h +++ b/src/NoteTrack.h @@ -90,7 +90,8 @@ class AUDACITY_DLL_API NoteTrack final const TimeWarper &warper, double semitones); static void DrawLabelControls - ( const NoteTrack *pTrack, wxDC & dc, const wxRect &rect ); + ( const NoteTrack *pTrack, wxDC & dc, const wxRect &rect, + int highlightedChannel = -1 ); int FindChannel(const wxRect &rect, int mx, int my); bool LabelClick(const wxRect &rect, int x, int y, bool right); diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index b14cb600b..a50eb04b0 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -2056,16 +2056,19 @@ void TrackInfo::MinimizeSyncLockDrawFunction } } +#include "tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.h" void TrackInfo::MidiControlsDrawFunction ( TrackPanelDrawingContext &context, const wxRect &rect, const Track *pTrack ) { #ifdef EXPERIMENTAL_MIDI_OUT + auto target = dynamic_cast( context.target.get() ); + auto channel = target ? target->GetChannel() : -1; auto &dc = context.dc; wxRect midiRect = rect; GetMidiControlsHorizontalBounds(rect, midiRect); NoteTrack::DrawLabelControls - ( static_cast(pTrack), dc, midiRect ); + ( static_cast(pTrack), dc, midiRect, channel ); #endif // EXPERIMENTAL_MIDI_OUT } diff --git a/src/tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.cpp b/src/tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.cpp index 9a4e1dd1d..ec47314ed 100644 --- a/src/tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.cpp +++ b/src/tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.cpp @@ -24,12 +24,23 @@ NoteTrackButtonHandle::NoteTrackButtonHandle : mpTrack{ pTrack } , mChannel{ channel } , mRect{ rect } -{} +{ + mChangeHighlight = RefreshCode::RefreshCell; +} NoteTrackButtonHandle::~NoteTrackButtonHandle() { } +UIHandle::Result NoteTrackButtonHandle::NeedChangeHighlight +(const NoteTrackButtonHandle &oldState, const NoteTrackButtonHandle &newState) +{ + if (oldState.GetChannel() != newState.GetChannel()) + // Repaint whenever the highlighted button is different + return RefreshCode::RefreshCell; + return 0; +} + UIHandlePtr NoteTrackButtonHandle::HitTest (std::weak_ptr &holder, const wxMouseState &state, const wxRect &rect, diff --git a/src/tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.h b/src/tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.h index bf5b4dbb6..b80068387 100644 --- a/src/tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.h +++ b/src/tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.h @@ -42,6 +42,10 @@ public: int GetChannel() const { return mChannel; } + static UIHandle::Result NeedChangeHighlight + (const NoteTrackButtonHandle &oldState, + const NoteTrackButtonHandle &newState); + protected: Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override;