various fixes to get lollipops to display (cue editor only so far)

This commit is contained in:
Paul Davis
2024-09-11 18:37:47 -06:00
parent c8924f4133
commit fa993ec9f4
7 changed files with 74 additions and 25 deletions

View File

@@ -260,7 +260,7 @@ MidiCueEditor::build_canvas ()
CANVAS_DEBUG_NAME (data_group, "cue data group");
bg = new CueMidiBackground (data_group);
_canvas_viewport->signal_size_allocate().connect (sigc::mem_fun(*this, &MidiCueEditor::canvas_allocate));
_canvas_viewport->signal_size_allocate().connect (sigc::mem_fun(*this, &MidiCueEditor::canvas_allocate), false);
// used as rubberband rect
rubberband_rect = new ArdourCanvas::Rectangle (data_group, ArdourCanvas::Rect (0.0, 0.0, 0.0, 0.0));
@@ -325,6 +325,8 @@ MidiCueEditor::canvas_allocate (Gtk::Allocation alloc)
_visible_canvas_width = alloc.get_width();
_visible_canvas_height = alloc.get_height();
std::cerr << "mce allocated " << alloc.get_width() << " x " << alloc.get_width() << " view = " << view << std::endl;
if (view) {
double timebars = n_timebars * timebar_height;
view->set_height (alloc.get_height() - timebars);

View File

@@ -27,9 +27,11 @@
#include "editing_context.h"
#include "editor_drag.h"
#include "hit.h"
#include "keyboard.h"
#include "midi_cue_view.h"
#include "midi_cue_velocity.h"
#include "note.h"
#include "velocity_display.h"
#include "pbd/i18n.h"
@@ -68,8 +70,13 @@ MidiCueView::MidiCueView (std::shared_ptr<ARDOUR::MidiTrack> mt,
CANVAS_DEBUG_NAME (automation_group, "cue automation group");
velocity_base = new ArdourCanvas::Rectangle (&parent);
CANVAS_DEBUG_NAME (velocity_base, "cue velocity base");
velocity_display = new MidiCueVelocityDisplay (editing_context(), midi_context(), *this, *velocity_base, 0x312244ff);
for (auto & ev : _events) {
velocity_display->add_note (ev.second);
}
set_extensible (true);
set_region (region);
}
@@ -83,8 +90,12 @@ MidiCueView::set_height (double h)
event_rect->set (ArdourCanvas::Rect (0.0, 0.0, ArdourCanvas::COORD_MAX, note_area_height));
midi_context().set_size (ArdourCanvas::COORD_MAX, note_area_height);
velocity_base->set (ArdourCanvas::Rect (0., note_area_height, ArdourCanvas::COORD_MAX, note_area_height + velocity_height));
automation_group->set (ArdourCanvas::Rect (0., note_area_height + velocity_height, ArdourCanvas::COORD_MAX, note_area_height + velocity_height + automation_height));
velocity_base->set_position (ArdourCanvas::Duple (0., note_area_height));
velocity_base->set (ArdourCanvas::Rect (0., 0., ArdourCanvas::COORD_MAX, velocity_height));
automation_group->set_position (ArdourCanvas::Duple (0., note_area_height + velocity_height));
automation_group->set (ArdourCanvas::Rect (0., 0., ArdourCanvas::COORD_MAX, automation_height));
view_changed ();
}
@@ -195,3 +206,21 @@ MidiCueView::ghost_sync_selection (NoteBase* nb)
velocity_display->note_selected (nb);
}
}
void
MidiCueView::update_sustained (Note* n)
{
MidiView::update_sustained (n);
if (velocity_display) {
velocity_display->update_note (n);
}
}
void
MidiCueView::update_hit (Hit* h)
{
MidiView::update_hit (h);
if (velocity_display) {
velocity_display->update_note (h);
}
}

View File

@@ -64,6 +64,10 @@ class MidiCueView : public MidiView
std::shared_ptr<Temporal::TempoMap const> tempo_map;
ArdourCanvas::Rectangle* event_rect;
uint32_t _slot_index;
void update_sustained (Note *);
void update_hit (Hit *);
};

View File

@@ -1590,14 +1590,14 @@ MidiView::note_in_region_range (const std::shared_ptr<NoteType> note, bool& visi
}
void
MidiView::update_note (NoteBase* note, bool update_ghost_regions)
MidiView::update_note (NoteBase* note)
{
Note* sus = NULL;
Hit* hit = NULL;
if ((sus = dynamic_cast<Note*>(note))) {
update_sustained(sus, update_ghost_regions);
update_sustained (sus);
} else if ((hit = dynamic_cast<Hit*>(note))) {
update_hit(hit, update_ghost_regions);
update_hit (hit);
}
}
@@ -1606,7 +1606,7 @@ MidiView::update_note (NoteBase* note, bool update_ghost_regions)
* @param update_ghost_regions true to update the note in any ghost regions that we have, otherwise false.
*/
void
MidiView::update_sustained (Note* ev, bool update_ghost_regions)
MidiView::update_sustained (Note* ev)
{
const std::shared_ptr<ARDOUR::MidiRegion> mr = midi_region();
std::shared_ptr<NoteType> note = ev->note();
@@ -1696,7 +1696,7 @@ MidiView::update_sustained (Note* ev, bool update_ghost_regions)
}
void
MidiView::update_hit (Hit* ev, bool update_ghost_regions)
MidiView::update_hit (Hit* ev)
{
std::shared_ptr<NoteType> note = ev->note();
const timepos_t note_time = _midi_region->source_beats_to_absolute_time (note->time());
@@ -2557,11 +2557,11 @@ MidiView::copy_selection (NoteBase* primary)
std::shared_ptr<NoteType> g (new NoteType (*((*i)->note())));
if (_midi_context.note_mode() == Sustained) {
Note* n = new Note (*this, _note_group, g);
update_sustained (n, false);
update_sustained (n);
note = n;
} else {
Hit* h = new Hit (*this, _note_group, 10, g);
update_hit (h, false);
update_hit (h);
note = h;
}
@@ -4023,7 +4023,7 @@ MidiView::update_ghost_note (double x, double y, uint32_t state)
_ghost_note->note()->set_channel (_midi_context.get_preferred_midi_channel ());
_ghost_note->note()->set_velocity (get_velocity_for_add (snapped_beats));
update_note (_ghost_note, false);
update_note (_ghost_note);
show_verbose_cursor (_ghost_note->note ());
}
@@ -4469,8 +4469,6 @@ MidiView::get_draw_length_beats (timepos_t const & pos) const
void
MidiView::quantize_selected_notes ()
{
std::cerr << "QSN!\n";
Quantize* quant = _editing_context.get_quantize_op ();
if (!quant) {

View File

@@ -532,9 +532,9 @@ class MidiView : public virtual sigc::trackable
friend class VelocityDisplay;
void sync_velocity_drag (double factor);
void update_note (NoteBase*, bool update_ghost_regions = true);
void update_sustained (Note *, bool update_ghost_regions = true);
void update_hit (Hit *, bool update_ghost_regions = true);
void update_note (NoteBase*);
virtual void update_sustained (Note *);
virtual void update_hit (Hit *);
void create_ghost_note (double, double, uint32_t state);
void update_ghost_note (double, double, uint32_t state);

View File

@@ -74,7 +74,6 @@ VelocityDisplay::VelocityDisplay (EditingContext& ec, MidiViewBackground& backgr
base.set_outline_color (UIConfiguration::instance().color ("automation track outline"));
base.set_outline (true);
base.set_outline_what (ArdourCanvas::Rectangle::What (ArdourCanvas::Rectangle::LEFT|ArdourCanvas::Rectangle::RIGHT));
}
VelocityDisplay::~VelocityDisplay ()
@@ -183,6 +182,10 @@ VelocityDisplay::add_note (NoteBase* nb)
void
VelocityDisplay::set_size_and_position (GhostEvent& gev)
{
if (base.get().empty()) {
return;
}
ArdourCanvas::Lollipop* l = dynamic_cast<ArdourCanvas::Lollipop*> (gev.item);
const double available_height = base.y1();
const double actual_height = ((dragging ? gev.velocity_while_editing : gev.event->note()->velocity()) / 127.0) * available_height;
@@ -190,21 +193,28 @@ VelocityDisplay::set_size_and_position (GhostEvent& gev)
if (gev.is_hit) {
/* compare to Hit::points , offset by w/2 */
l->set (ArdourCanvas::Duple (gev.event->x0() + (gev.event->x1() - gev.event->x0()) / 2, base.y1() - actual_height), actual_height, lollipop_radius * scale);
l->set (ArdourCanvas::Duple (gev.event->x0() + (gev.event->x1() - gev.event->x0()) / 2, base.height() - actual_height), actual_height, lollipop_radius * scale);
} else {
l->set (ArdourCanvas::Duple (gev.event->x0(), base.y1() - actual_height), actual_height, lollipop_radius * scale);
l->set (ArdourCanvas::Duple (gev.event->x0(), base.height() - actual_height), actual_height, lollipop_radius * scale);
std::cerr << "place loli @ " << ArdourCanvas::Duple (gev.event->x0(), base.height() - actual_height) << " h: " << actual_height << " r: " << lollipop_radius * scale << " of " << available_height
<< " ah " << actual_height << " from " << base.whoami() << " = " << base.get() << " bh " << base.height() << std::endl;
}
}
void
VelocityDisplay::update_note (GhostEvent* gev)
VelocityDisplay::update_note (NoteBase* nb)
{
set_size_and_position (*gev);
gev->item->set_fill_color (gev->event->base_color());
GhostEvent* gev = GhostEvent::find (nb->note(), events, _optimization_iterator);
if (!gev) {
return;
}
update_ghost_event (gev);
}
void
VelocityDisplay::update_hit (GhostEvent* gev)
VelocityDisplay::update_ghost_event (GhostEvent* gev)
{
set_size_and_position (*gev);
gev->item->set_fill_color (gev->event->base_color());
@@ -310,6 +320,7 @@ VelocityDisplay::y_position_to_velocity (double y) const
void
VelocityDisplay::note_selected (NoteBase* ev)
{
std::cerr << "Look for event in " << events.size() << std::endl;
GhostEvent* gev = GhostEvent::find (ev->note(), events, _optimization_iterator);
if (!gev) {

View File

@@ -47,8 +47,13 @@ class VelocityDisplay
void redisplay();
void add_note(NoteBase*);
void update_note (GhostEvent* note);
void update_hit (GhostEvent* hit);
void update_note (NoteBase*);
void update_ghost_event (GhostEvent*);
void update_note (GhostEvent* gev) { update_ghost_event (gev); }
void update_hit (GhostEvent* gev) { update_ghost_event (gev); }
virtual void remove_note (NoteBase*) = 0;
void note_selected (NoteBase*);
void clear ();