attempt to properly manage MIDI note display of selected status

Whether to display the selected outline depends on BOTH whether the note is
selected, and whether we are in an internal editing mode.
This commit is contained in:
Paul Davis 2020-05-01 17:39:03 -06:00
parent 13c0145890
commit 044be53616
3 changed files with 53 additions and 12 deletions

View File

@ -469,11 +469,19 @@ MidiRegionView::enter_internal (uint32_t state)
if (frame_handle_end) {
frame_handle_end->lower_to_bottom();
}
for (Events::iterator it = _events.begin(); it != _events.end(); ++it) {
it->second->set_hide_selection (false);
}
}
void
MidiRegionView::leave_internal()
{
for (Events::iterator it = _events.begin(); it != _events.end(); ++it) {
it->second->set_hide_selection (true);
}
hide_verbose_cursor ();
remove_ghost_note ();
_entered_note = 0;
@ -2440,8 +2448,12 @@ MidiRegionView::add_to_selection (NoteBase* ev)
}
if (selection_was_empty) {
PublicEditor& editor (trackview.editor());
editor.get_selection().add (this);
/* first note selected in this region, force Editor region
* selection to this region.
*/
trackview.editor().set_selected_midi_region_view (*this);
}
}

View File

@ -68,7 +68,7 @@ NoteBase::NoteBase(MidiRegionView& region, bool with_events, const boost::shared
, _state(None)
, _note(note)
, _with_events (with_events)
, _selected(false)
, _flags (Flags (0))
, _valid (true)
, _mouse_x_fraction (-1.0)
, _mouse_y_fraction (-1.0)
@ -142,10 +142,10 @@ NoteBase::on_channel_selection_change(uint16_t selection)
if ( (selection & (1 << _note->channel())) == 0 ) {
const Gtkmm2ext::Color inactive_ch = UIConfiguration::instance().color ("midi note inactive channel");
set_fill_color(inactive_ch);
set_outline_color(calculate_outline(inactive_ch, _selected));
set_outline_color(calculate_outline(inactive_ch, (_flags == Selected)));
} else {
// set the color according to the notes selection state
set_selected(_selected);
set_selected (_flags == Selected);
}
// this forces the item to update..... maybe slow...
_item->hide();
@ -166,12 +166,16 @@ NoteBase::set_selected(bool selected)
return;
}
_selected = selected;
if (selected) {
_flags = Flags (_flags | Selected);
} else {
_flags = Flags (_flags & ~Selected);
}
const uint32_t base_col = base_color();
set_fill_color (base_col);
set_outline_color(calculate_outline(base_col, _selected));
set_outline_color(calculate_outline(base_col, (_flags == Selected)));
}
#define SCALE_USHORT_TO_UINT8_T(x) ((x) / 257)
@ -364,3 +368,21 @@ NoteBase::meter_style_fill_color(uint8_t vel, bool /* selected */)
return velocity_color_table[vel];
}
void
NoteBase::set_hide_selection (bool yn)
{
if (yn) {
_flags = Flags (_flags | HideSelection);
} else {
_flags = Flags (_flags & ~HideSelection);
}
if (_flags & Selected) {
/* maybe (?) change outline color */
set_outline_color (calculate_outline (base_color(), !yn));
}
/* no need to redo color if it wasn't selected and we just changed
* "hide selected" since nothing will change
*/
}

View File

@ -55,7 +55,13 @@ namespace ArdourCanvas {
*/
class NoteBase : public sigc::trackable
{
public:
private:
enum Flags {
Selected = 0x1,
HideSelection = 0x2,
};
public:
typedef Evoral::Note<Temporal::Beats> NoteType;
NoteBase (MidiRegionView& region, bool, const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>());
@ -71,8 +77,9 @@ public:
void invalidate ();
void validate ();
bool selected() const { return _selected; }
bool selected() const { return _flags & Selected; }
void set_selected(bool yn);
void set_hide_selection (bool yn);
virtual void move_event(double dx, double dy) = 0;
@ -108,8 +115,8 @@ public:
static Gtkmm2ext::Color meter_style_fill_color(uint8_t vel, bool selected);
/// calculate outline colors from fill colors of notes
inline static uint32_t calculate_outline(uint32_t color, bool selected=false) {
if (selected) {
inline static uint32_t calculate_outline(uint32_t color, bool showing_selection = false) {
if (showing_selection) {
return _selected_col;
} else {
return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
@ -132,7 +139,7 @@ protected:
const boost::shared_ptr<NoteType> _note;
bool _with_events;
bool _own_note;
bool _selected;
Flags _flags;
bool _valid;
float _mouse_x_fraction;
float _mouse_y_fraction;