From 51531246648b2b25cae694426c3e6b57b65f2c40 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 10 Feb 2021 22:27:27 -0700 Subject: [PATCH] change (GUI) Marker objects to accept any Canvas::Item as parent, and use this to draw BBT position markers in the BBT ruler --- gtk2_ardour/editor.h | 4 ++-- gtk2_ardour/editor_markers.cc | 6 +++--- gtk2_ardour/editor_tempodisplay.cc | 14 +++++++++++++- gtk2_ardour/marker.cc | 14 ++++++++++---- gtk2_ardour/marker.h | 16 ++++++++-------- libs/canvas/ruler.cc | 2 ++ 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index bae3556074..df12b5f611 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -748,7 +748,7 @@ private: LocationMarkerMap location_markers; void update_marker_labels (); - void update_marker_labels (ArdourCanvas::Container*); + void update_marker_labels (ArdourCanvas::Item*); void check_marker_label (ArdourMarker*); /** A set of lists of Markers that are in each of the canvas groups @@ -757,7 +757,7 @@ private: * a marker has moved we can decide whether we need to update the labels * for all markers or for just a few. */ - std::map > _sorted_marker_lists; + std::map > _sorted_marker_lists; void remove_sorted_marker (ArdourMarker*); void hide_marker (ArdourCanvas::Item*, GdkEvent*); diff --git a/gtk2_ardour/editor_markers.cc b/gtk2_ardour/editor_markers.cc index e2ce0f2879..e17e93aa6a 100644 --- a/gtk2_ardour/editor_markers.cc +++ b/gtk2_ardour/editor_markers.cc @@ -326,14 +326,14 @@ struct MarkerComparator { void Editor::update_marker_labels () { - for (std::map >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) { + for (std::map >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) { update_marker_labels (i->first); } } /** Look at all markers in a group and update label widths */ void -Editor::update_marker_labels (ArdourCanvas::Container* group) +Editor::update_marker_labels (ArdourCanvas::Item* group) { list& sorted = _sorted_marker_lists[group]; @@ -1838,7 +1838,7 @@ Editor::toggle_marker_lines () void Editor::remove_sorted_marker (ArdourMarker* m) { - for (std::map >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) { + for (std::map >::iterator i = _sorted_marker_lists.begin(); i != _sorted_marker_lists.end(); ++i) { i->second.remove (m); } } diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index 783c7e82cc..ca210e9418 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -108,8 +108,20 @@ Editor::draw_metric_marks (TempoMap::Metrics const & metrics) for (TempoMap::Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) { Temporal::MeterPoint *ms; Temporal::TempoPoint *ts; + Temporal::MusicTimePoint *mtp; - if ((ms = dynamic_cast(*i)) != 0) { + /* must check MusicTimePoint first, since it IS-A TempoPoint + * and MeterPoint. + */ + + if ((mtp = dynamic_cast(*i)) != 0) { + + if (ms->map().time_domain() == BeatTime) { + metric_marks.push_back (new BBTMarker (*this, *bbt_ruler, UIConfiguration::instance().color ("meter marker music"), "bar!", *mtp)); + } else { + metric_marks.push_back (new BBTMarker (*this, *bbt_ruler, UIConfiguration::instance().color ("meter marker"), "foo!", *mtp)); + } + } else if ((ms = dynamic_cast(*i)) != 0) { snprintf (buf, sizeof(buf), "%d/%d", ms->divisions_per_bar(), ms->note_value ()); if (ms->map().time_domain() == BeatTime) { metric_marks.push_back (new MeterMarker (*this, *meter_group, UIConfiguration::instance().color ("meter marker music"), buf, *ms)); diff --git a/gtk2_ardour/marker.cc b/gtk2_ardour/marker.cc index 5ddfb2cdf7..523f80da17 100644 --- a/gtk2_ardour/marker.cc +++ b/gtk2_ardour/marker.cc @@ -110,6 +110,7 @@ ArdourMarker::ArdourMarker (PublicEditor& ed, ArdourCanvas::Container& parent, g * * TempoMark: * MeterMark: + * BBTPosition * * (3,0) * / \ @@ -185,6 +186,7 @@ ArdourMarker::ArdourMarker (PublicEditor& ed, ArdourCanvas::Container& parent, g case Tempo: case Meter: + case BBTPosition: points = new ArdourCanvas::Points (); points->push_back (ArdourCanvas::Duple ( M3, 0.0)); points->push_back (ArdourCanvas::Duple ( M6, MH * .6)); @@ -269,8 +271,11 @@ ArdourMarker::ArdourMarker (PublicEditor& ed, ArdourCanvas::Container& parent, g _position = pos; unit_position = editor.sample_to_pixel (pos.samples()); + std::cerr << "1marker @ " << unit_position << " from sample " << pos.samples() << std::endl; unit_position -= _shift; + std::cerr << "2marker @ " << unit_position << " from sample " << pos.samples() << " shift was " << _shift << std::endl; + group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 1)); #ifdef CANVAS_DEBUG group->name = string_compose ("Marker::group for %1", annotation); @@ -340,7 +345,7 @@ ArdourMarker::~ArdourMarker () delete points; } -void ArdourMarker::reparent(ArdourCanvas::Container & parent) +void ArdourMarker::reparent(ArdourCanvas::Item & parent) { group->reparent (&parent); _parent = &parent; @@ -631,7 +636,7 @@ ArdourMarker::set_right_label_limit (double p) /***********************************************************************/ -TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text, +TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Item& parent, guint32 rgba, const string& text, Temporal::TempoPoint& temp) : ArdourMarker (editor, parent, rgba, text, Tempo, temp.time(), false) , _tempo (temp) @@ -672,7 +677,7 @@ TempoMarker::reset_tempo (Temporal::TempoPoint & t) /***********************************************************************/ -MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text, Temporal::MeterPoint& m) +MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Item& parent, guint32 rgba, const string& text, Temporal::MeterPoint& m) : ArdourMarker (editor, parent, rgba, text, Meter, m.time(), false) , _meter (m) { @@ -691,10 +696,11 @@ MeterMarker::reset_meter (Temporal::MeterPoint & m) /***********************************************************************/ -BBTMarker::BBTMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text, Temporal::MusicTimePoint& p) +BBTMarker::BBTMarker (PublicEditor& editor, ArdourCanvas::Item& parent, guint32 rgba, const string& text, Temporal::MusicTimePoint& p) : ArdourMarker (editor, parent, rgba, text, BBTPosition, p.time(), false) , _point (p) { + cerr << "NEW BBT MARKER!\n"; group->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_bbt_marker_event), group, this)); } diff --git a/gtk2_ardour/marker.h b/gtk2_ardour/marker.h index cd5f183f63..43c43d7dc9 100644 --- a/gtk2_ardour/marker.h +++ b/gtk2_ardour/marker.h @@ -70,7 +70,7 @@ public: ArdourMarker (PublicEditor& editor, ArdourCanvas::Container &, guint32 rgba, const std::string& text, Type, ARDOUR::timepos_t const & position, bool handle_events = true, RegionView* rv = 0); - + virtual ~ArdourMarker (); static PBD::Signal1 CatchDeletion; @@ -92,8 +92,8 @@ public: ARDOUR::timepos_t position() const { return _position; } - ArdourCanvas::Container * get_parent() { return _parent; } - void reparent (ArdourCanvas::Container & parent); + ArdourCanvas::Item * get_parent() { return _parent; } + void reparent (ArdourCanvas::Item & parent); void hide (); void show (); @@ -118,8 +118,8 @@ protected: Pango::FontDescription name_font; - ArdourCanvas::Container* _parent; - ArdourCanvas::Container *group; + ArdourCanvas::Item* _parent; + ArdourCanvas::Item *group; ArdourCanvas::Polygon *mark; ArdourCanvas::Text *_name_item; ArdourCanvas::Points *points; @@ -159,7 +159,7 @@ private: class TempoMarker : public ArdourMarker { public: - TempoMarker (PublicEditor& editor, ArdourCanvas::Container &, guint32 rgba, const std::string& text, Temporal::TempoPoint&); + TempoMarker (PublicEditor& editor, ArdourCanvas::Item &, guint32 rgba, const std::string& text, Temporal::TempoPoint&); ~TempoMarker (); void reset_tempo (Temporal::TempoPoint & t); @@ -174,7 +174,7 @@ class TempoMarker : public ArdourMarker class MeterMarker : public ArdourMarker { public: - MeterMarker (PublicEditor& editor, ArdourCanvas::Container &, guint32 rgba, const std::string& text, Temporal::MeterPoint&); + MeterMarker (PublicEditor& editor, ArdourCanvas::Item &, guint32 rgba, const std::string& text, Temporal::MeterPoint&); ~MeterMarker (); void reset_meter (Temporal::MeterPoint & m); @@ -188,7 +188,7 @@ class MeterMarker : public ArdourMarker class BBTMarker : public ArdourMarker { public: - BBTMarker (PublicEditor& editor, ArdourCanvas::Container &, guint32 rgba, const std::string& text, Temporal::MusicTimePoint&); + BBTMarker (PublicEditor& editor, ArdourCanvas::Item &, guint32 rgba, const std::string& text, Temporal::MusicTimePoint&); ~BBTMarker (); void reset_point (Temporal::MusicTimePoint &); diff --git a/libs/canvas/ruler.cc b/libs/canvas/ruler.cc index 9fbeb0550e..84fc5a2a99 100644 --- a/libs/canvas/ruler.cc +++ b/libs/canvas/ruler.cc @@ -234,6 +234,8 @@ Ruler::render (Rect const & area, Cairo::RefPtr cr) const } + render_children (area, cr); + /* done! */ }