lollis: color management during drag, and verbose cursor

This commit is contained in:
Paul Davis 2023-06-21 17:32:52 -06:00
parent c75b9a11ef
commit 25bb43e285
3 changed files with 65 additions and 20 deletions

View File

@ -181,32 +181,36 @@ NoteBase::set_selected(bool selected)
#define SCALE_USHORT_TO_UINT8_T(x) ((x) / 257)
uint32_t
NoteBase::base_color()
NoteBase::base_color ()
{
return base_color (_note->velocity(), _region.color_mode(), _region.midi_stream_view()->get_region_color(), _note->channel(), selected());
}
uint32_t
NoteBase::base_color (int velocity, ARDOUR::ColorMode color_mode, Gtkmm2ext::Color default_color, int channel, bool selected)
{
using namespace ARDOUR;
ColorMode mode = _region.color_mode();
const uint8_t min_opacity = 15;
uint8_t opacity = std::max(min_opacity, uint8_t(_note->velocity() + _note->velocity()));
uint8_t opacity = std::max(min_opacity, uint8_t(velocity + velocity));
switch (mode) {
case TrackColor:
switch (color_mode) {
case ARDOUR::TrackColor:
{
const uint32_t region_color = _region.midi_stream_view()->get_region_color();
const uint32_t region_color = default_color;
return UINT_INTERPOLATE (UINT_RGBA_CHANGE_A (region_color, opacity), _selected_col,
0.5);
}
case ChannelColors:
return UINT_INTERPOLATE (UINT_RGBA_CHANGE_A (NoteBase::midi_channel_colors[_note->channel()], opacity),
case ARDOUR::ChannelColors:
return UINT_INTERPOLATE (UINT_RGBA_CHANGE_A (NoteBase::midi_channel_colors[channel], opacity),
_selected_col, 0.5);
default:
if (UIConfiguration::instance().get_use_note_color_for_velocity()) {
return meter_style_fill_color(_note->velocity(), selected());
return meter_style_fill_color(velocity, selected);
} else {
const uint32_t region_color = _region.midi_stream_view()->get_region_color();
const uint32_t region_color = default_color;
return UINT_INTERPOLATE (UINT_RGBA_CHANGE_A (region_color, opacity), _selected_col,
0.5);
}

View File

@ -27,6 +27,8 @@
#include "canvas/types.h"
#include "gtkmm2ext/colors.h"
#include "ardour/types.h"
#include "rgb_macros.h"
#include "ui_config.h"
@ -85,6 +87,7 @@ class NoteBase : public sigc::trackable
virtual void move_event(double dx, double dy) = 0;
uint32_t base_color();
static uint32_t base_color (int velocity, ARDOUR::ColorMode color_mode, Gtkmm2ext::Color, int channel, bool selected);
void show_velocity();
void hide_velocity();
@ -129,7 +132,7 @@ class NoteBase : public sigc::trackable
/// hue circle divided into 16 equal-looking parts, courtesy Thorsten Wilms
static const uint32_t midi_channel_colors[16];
bool mouse_near_ends () const;
virtual bool big_enough_to_trim () const;

View File

@ -41,6 +41,7 @@
#include "note_base.h"
#include "public_editor.h"
#include "ui_config.h"
#include "verbose_cursor.h"
#include "pbd/i18n.h"
@ -84,7 +85,7 @@ VelocityGhostRegion::add_note (NoteBase* nb)
l->set_data (X_("ghostregionview"), this);
l->set_data (X_("note"), nb);
event->item->set_fill_color (UIConfiguration::instance().color_mod(nb->base_color(), "ghost track midi fill"));
event->item->set_fill_color (nb->base_color());
event->item->set_outline_color (_outline);
MidiStreamView* mv = midi_view();
@ -108,15 +109,17 @@ VelocityGhostRegion::set_size_and_position (GhostEvent& ev)
}
void
VelocityGhostRegion::update_note (GhostEvent* ev)
VelocityGhostRegion::update_note (GhostEvent* gev)
{
set_size_and_position (*ev);
set_size_and_position (*gev);
gev->item->set_fill_color (gev->event->base_color());
}
void
VelocityGhostRegion::update_hit (GhostEvent* ev)
VelocityGhostRegion::update_hit (GhostEvent* gev)
{
set_size_and_position (*ev);
set_size_and_position (*gev);
gev->item->set_fill_color (gev->event->base_color());
}
void
@ -127,7 +130,11 @@ VelocityGhostRegion::remove_note (NoteBase*)
void
VelocityGhostRegion::set_colors ()
{
base_rect->set_fill_color (Gtkmm2ext::Color (0xff000085));
base_rect->set_fill_color (UIConfiguration::instance().color ("ghost track base"));
for (auto & gev : events) {
gev.second->item->set_fill_color (gev.second->event->base_color());
}
}
void
@ -161,15 +168,46 @@ VelocityGhostRegion::drag_lolli (ArdourCanvas::Lollipop* l, GdkEventMotion* ev)
mrv->sync_velocity_drag (factor);
MidiRegionView::Selection const & sel (mrv->selection());
int verbose_velocity = -1;
GhostEvent* primary_ghost = 0;
for (auto & s : sel) {
GhostEvent* x = find_event (s->note());
if (x) {
ArdourCanvas::Lollipop* l = dynamic_cast<ArdourCanvas::Lollipop*> (x->item);
l->set (ArdourCanvas::Duple (l->x(), l->y0() - delta), l->length() + delta, lollipop_radius);
ArdourCanvas::Lollipop* lolli = dynamic_cast<ArdourCanvas::Lollipop*> (x->item);
lolli->set (ArdourCanvas::Duple (lolli->x(), lolli->y0() - delta), lolli->length() + delta, lollipop_radius);
/* note: length is now set to the new value */
const int newvel = floor (127. * (l->length() / r.height()));
/* since we're not actually changing the note velocity
(yet), we have to use the static method to compute
the color.
*/
lolli->set_fill_color (NoteBase::base_color (newvel, mrv->color_mode(), mrv->midi_stream_view()->get_region_color(), x->event->note()->channel(), true));
if (l == lolli) {
/* This is the value we will display */
verbose_velocity = newvel;
primary_ghost = x;
}
}
}
assert (verbose_velocity >= 0);
char buf[128];
const int oldvel = primary_ghost->event->note()->velocity();
if (verbose_velocity > oldvel) {
snprintf (buf, sizeof (buf), "Velocity %d (+%d)", verbose_velocity, verbose_velocity - oldvel);
} else if (verbose_velocity == oldvel) {
snprintf (buf, sizeof (buf), "Velocity %d", verbose_velocity);
} else {
snprintf (buf, sizeof (buf), "Velocity %d (%d)", verbose_velocity, verbose_velocity - oldvel);
}
trackview.editor().verbose_cursor()->set (buf);
trackview.editor().verbose_cursor()->show ();
trackview.editor().verbose_cursor()->set_offset (ArdourCanvas::Duple (10., 10.));
}
int