1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-03 00:59:43 +02:00

Highlight MIDI channel buttons

This commit is contained in:
Paul Licameli 2017-06-22 00:23:17 -04:00
parent 25641ae568
commit 44d6d5f427
5 changed files with 32 additions and 6 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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<NoteTrackButtonHandle*>( context.target.get() );
auto channel = target ? target->GetChannel() : -1;
auto &dc = context.dc;
wxRect midiRect = rect;
GetMidiControlsHorizontalBounds(rect, midiRect);
NoteTrack::DrawLabelControls
( static_cast<const NoteTrack *>(pTrack), dc, midiRect );
( static_cast<const NoteTrack *>(pTrack), dc, midiRect, channel );
#endif // EXPERIMENTAL_MIDI_OUT
}

View File

@ -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<NoteTrackButtonHandle> &holder,
const wxMouseState &state, const wxRect &rect,

View File

@ -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;