From e24d1d069dd35baded272884818051e2c9bf8ce1 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 8 Jan 2024 14:35:15 -0700 Subject: [PATCH] all streamviews are now ViewBackgrounds This new inheritance heirarchy lets us share (a very small piece of) code between streamviews in the Editor and the nascent piano roll object on the cue page. --- gtk2_ardour/automation_streamview.h | 2 +- gtk2_ardour/midi_cue_editor.cc | 28 +++++++++++++++ gtk2_ardour/midi_cue_editor.h | 10 +++++- gtk2_ardour/midi_streamview.cc | 8 +++++ gtk2_ardour/midi_streamview.h | 1 + gtk2_ardour/midi_view_background.cc | 2 +- gtk2_ardour/midi_view_background.h | 18 +++++++--- gtk2_ardour/streamview.h | 4 ++- gtk2_ardour/view_background.cc | 41 +++++++++++++++++++++ gtk2_ardour/view_background.h | 55 +++++++++++++++++++++++++++++ 10 files changed, 160 insertions(+), 9 deletions(-) create mode 100644 gtk2_ardour/view_background.cc create mode 100644 gtk2_ardour/view_background.h diff --git a/gtk2_ardour/automation_streamview.h b/gtk2_ardour/automation_streamview.h index c5265b9557..e79b56aafe 100644 --- a/gtk2_ardour/automation_streamview.h +++ b/gtk2_ardour/automation_streamview.h @@ -52,7 +52,7 @@ public: void redisplay_track (); - inline double contents_height() const { + double contents_height() const { return (_trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2); } diff --git a/gtk2_ardour/midi_cue_editor.cc b/gtk2_ardour/midi_cue_editor.cc index 7ce1e81591..bba767b768 100644 --- a/gtk2_ardour/midi_cue_editor.cc +++ b/gtk2_ardour/midi_cue_editor.cc @@ -22,7 +22,9 @@ #include "canvas/scroll_group.h" #include "canvas/rectangle.h" +#include "midi_cue_background.h" #include "midi_cue_editor.h" +#include "midi_view.h" #include "ui_config.h" #include "verbose_cursor.h" @@ -93,6 +95,13 @@ MidiCueEditor::build_canvas () // used as rubberband rect rubberband_rect = new ArdourCanvas::Rectangle (hv_scroll_group, ArdourCanvas::Rect (0.0, 0.0, 0.0, 0.0)); rubberband_rect->hide(); + + ArdourCanvas::Text* hw = new ArdourCanvas::Text (hv_scroll_group); + hw->set ("hello, world"); + hw->set_fill_color (Gtkmm2ext::Color (0xff0000ff)); + + std::cerr << "New CMB\n"; + bg = new CueMidiBackground (hv_scroll_group); } @@ -174,3 +183,22 @@ MidiCueEditor::canvas_note_event (GdkEvent* event, ArdourCanvas::Item*) { return false; } + +Gtk::Widget& +MidiCueEditor::viewport() +{ + return *_canvas_viewport; +} + +void +MidiCueEditor::set_region (std::shared_ptr t, std::shared_ptr r) +{ + // delete view; + // view = nullptr; + + if (!t || !r) { + return; + } + + // view = new MidiView (t, hv_scroll_group, *this, *bg, 0xff0000ff); +} diff --git a/gtk2_ardour/midi_cue_editor.h b/gtk2_ardour/midi_cue_editor.h index c2850099fb..04743885a4 100644 --- a/gtk2_ardour/midi_cue_editor.h +++ b/gtk2_ardour/midi_cue_editor.h @@ -34,6 +34,9 @@ namespace ArdourCanvas { class ScrollGroup; } +class MidiView; +class CueMidiBackground; + class MidiCueEditor : public CueEditor { public: @@ -41,7 +44,7 @@ class MidiCueEditor : public CueEditor ~MidiCueEditor (); ArdourCanvas::Container* get_noscroll_group() const { return no_scroll_group; } - Gtk::Widget& viewport() { return *_canvas_viewport; } + Gtk::Widget& viewport(); double visible_canvas_width() const { return _visible_canvas_width; } samplecnt_t current_page_samples() const; @@ -59,6 +62,8 @@ class MidiCueEditor : public CueEditor void apply_midi_note_edit_op (ARDOUR::MidiOperator& op, const RegionSelection& rs); PBD::Command* apply_midi_note_edit_op_to_region (ARDOUR::MidiOperator& op, MidiRegionView& mrv); + void set_region (std::shared_ptr, std::shared_ptr); + protected: Temporal::timepos_t snap_to_grid (Temporal::timepos_t const & start, Temporal::RoundMode direction, @@ -100,6 +105,9 @@ class MidiCueEditor : public CueEditor ArdourCanvas::Rectangle* transport_loop_range_rect; + CueMidiBackground* bg; + MidiView* view; + void build_canvas (); }; diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc index 3c2249a66c..ae52ecb2ee 100644 --- a/gtk2_ardour/midi_streamview.cc +++ b/gtk2_ardour/midi_streamview.cc @@ -207,11 +207,19 @@ MidiStreamView::display_track (std::shared_ptr tr) { StreamView::display_track (tr); + std::cerr << "MSV @ " << this << " dnl\n"; draw_note_lines(); NoteRangeChanged(); /* EMIT SIGNAL*/ } +void +MidiStreamView::update_contents_height () +{ + StreamView::update_contents_height(); + MidiViewBackground::update_contents_height (); +} + void MidiStreamView::update_contents_metrics(std::shared_ptr r) { diff --git a/gtk2_ardour/midi_streamview.h b/gtk2_ardour/midi_streamview.h index 32fc47b1cd..47d9d85bcc 100644 --- a/gtk2_ardour/midi_streamview.h +++ b/gtk2_ardour/midi_streamview.h @@ -104,6 +104,7 @@ private: void display_region(MidiRegionView* region_view, bool load_model); void display_track (std::shared_ptr tr); + void update_contents_height (); void update_contents_metrics (std::shared_ptr r); void color_handler (); void apply_note_range_to_children (); diff --git a/gtk2_ardour/midi_view_background.cc b/gtk2_ardour/midi_view_background.cc index 0436891642..ec347ab6c9 100644 --- a/gtk2_ardour/midi_view_background.cc +++ b/gtk2_ardour/midi_view_background.cc @@ -45,7 +45,7 @@ MidiViewBackground::MidiViewBackground (ArdourCanvas::Item* parent) { _note_lines->lower_to_bottom(); - color_handler (); + // color_handler (); UIConfiguration::instance().ColorsChanged.connect(sigc::mem_fun(*this, &MidiViewBackground::color_handler)); UIConfiguration::instance().ParameterChanged.connect(sigc::mem_fun(*this, &MidiViewBackground::parameter_changed)); diff --git a/gtk2_ardour/midi_view_background.h b/gtk2_ardour/midi_view_background.h index 9c79422287..70fb731383 100644 --- a/gtk2_ardour/midi_view_background.h +++ b/gtk2_ardour/midi_view_background.h @@ -29,16 +29,26 @@ #include "ardour/types.h" +#include "gtkmm2ext/colors.h" + +#include "view_background.h" + namespace ArdourCanvas { class Item; class LineSet; } -class MidiViewBackground +/** A class that provides various context for a MidiVieww: + = note ranges + * color information + * etc. + */ + +class MidiViewBackground : public virtual ViewBackground { public: MidiViewBackground (ArdourCanvas::Item* parent); - virtual ~MidiViewBackground (); + ~MidiViewBackground (); Gtk::Adjustment note_range_adjustment; @@ -62,8 +72,6 @@ class MidiViewBackground void update_note_range(uint8_t note_num); - virtual double contents_height() const = 0; - double note_to_y (uint8_t note) const { return contents_height() - (note + 1 - lowest_note()) * note_height() + 1; } @@ -103,9 +111,9 @@ class MidiViewBackground void color_handler (); void parameter_changed (std::string const &); void note_range_adjustment_changed(); - void update_contents_height (); void draw_note_lines(); bool update_data_note_range(uint8_t min, uint8_t max); + void update_contents_height (); virtual void apply_note_range_to_children () = 0; virtual bool updates_suspended() const { return false; } }; diff --git a/gtk2_ardour/streamview.h b/gtk2_ardour/streamview.h index 024551f96c..477331cc09 100644 --- a/gtk2_ardour/streamview.h +++ b/gtk2_ardour/streamview.h @@ -31,7 +31,9 @@ #include "pbd/signals.h" #include "ardour/location.h" + #include "enums.h" +#include "view_background.h" namespace Gdk { class Color; @@ -64,7 +66,7 @@ class RegionSelection; class CrossfadeView; class Selection; -class StreamView : public sigc::trackable, public PBD::ScopedConnectionList +class StreamView : public sigc::trackable, public PBD::ScopedConnectionList, public virtual ViewBackground { public: virtual ~StreamView (); diff --git a/gtk2_ardour/view_background.cc b/gtk2_ardour/view_background.cc new file mode 100644 index 0000000000..022cb0baa8 --- /dev/null +++ b/gtk2_ardour/view_background.cc @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2006-2014 David Robillard + * Copyright (C) 2007 Doug McLain + * Copyright (C) 2008-2017 Paul Davis + * Copyright (C) 2009-2012 Carl Hetherington + * Copyright (C) 2014-2019 Robin Gareus + * Copyright (C) 2015 Tim Mayberry + * Copyright (C) 2016 Nick Mainsbridge + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "canvas/line_set.h" + +#include "view_background.h" +#include "ui_config.h" + +using namespace std; + +ViewBackground::ViewBackground () +{ + UIConfiguration::instance().ColorsChanged.connect(sigc::mem_fun(*this, &ViewBackground::color_handler)); + UIConfiguration::instance().ParameterChanged.connect(sigc::mem_fun(*this, &ViewBackground::parameter_changed)); +} + +ViewBackground::~ViewBackground() +{ +} + diff --git a/gtk2_ardour/view_background.h b/gtk2_ardour/view_background.h new file mode 100644 index 0000000000..27783d415b --- /dev/null +++ b/gtk2_ardour/view_background.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2006-2014 David Robillard + * Copyright (C) 2007 Doug McLain + * Copyright (C) 2008-2017 Paul Davis + * Copyright (C) 2009-2012 Carl Hetherington + * Copyright (C) 2016-2017 Robin Gareus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __gtk2_ardour_view_background_h__ +#define __gtk2_ardour_view_background_h__ + +#include + +#include "gtkmm2ext/colors.h" + +namespace ArdourCanvas { + class Item; +} + +/** A class that provides limited context for a View + */ + +class ViewBackground +{ + public: + ViewBackground (); + virtual ~ViewBackground (); + + virtual double contents_height() const { return 0.; } + + /** @return y position, or -1 if hidden */ + virtual double y_position () const { return 0.; } + + protected: + virtual void update_contents_height () {} + virtual void color_handler () {} + virtual void parameter_changed (std::string const &) {} +}; + + +#endif /* __gtk2_ardour_view_background_h__ */