From 3bbe54f07aab182d0a9febd45be3c506a24fb415 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 10 Dec 2021 08:54:38 -0700 Subject: [PATCH] audio clip editor: draw entire source file(s), not just region --- gtk2_ardour/audio_clip_editor.cc | 39 +++++++++++++++++++++++++++----- gtk2_ardour/audio_clip_editor.h | 6 +++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/gtk2_ardour/audio_clip_editor.cc b/gtk2_ardour/audio_clip_editor.cc index 36f771be4b..012fc71fe4 100644 --- a/gtk2_ardour/audio_clip_editor.cc +++ b/gtk2_ardour/audio_clip_editor.cc @@ -33,7 +33,9 @@ #include "ardour/audioregion.h" #include "ardour/location.h" #include "ardour/profile.h" +#include "ardour/region_factory.h" #include "ardour/session.h" +#include "ardour/source.h" #include "widgets/ardour_button.h" @@ -57,6 +59,7 @@ using std::max; /* ------------ */ AudioClipEditor::AudioClipEditor () + : spp (0) { set_background_color (UIConfiguration::instance().color (X_("theme:bg"))); @@ -90,15 +93,31 @@ AudioClipEditor::set_region (boost::shared_ptr r) drop_waves (); uint32_t n_chans = r->n_channels (); + samplecnt_t len; + + len = r->source (0)->length().samples (); for (uint32_t n = 0; n < n_chans; ++n) { - WaveView* wv = new WaveView (frame, r); + + boost::shared_ptr wr = RegionFactory::get_whole_region_for_source (r->source (n)); + if (!wr) { + continue; + } + + boost::shared_ptr war = boost::dynamic_pointer_cast (wr); + if (!war) { + continue; + } + + WaveView* wv = new WaveView (frame, war); wv->set_channel (n); + wv->set_show_zero_line (false); + wv->set_clip_level (1.0); + waves.push_back (wv); } - std::cerr << "Now have " << waves.size() << " waves" << std::endl; - + set_wave_spp (len); set_wave_heights (frame->get().height() - 2.0); set_waveform_colors (); } @@ -114,6 +133,17 @@ AudioClipEditor::on_size_allocate (Gtk::Allocation& alloc) set_wave_heights (r.height() - 2.0); } +void +AudioClipEditor::set_wave_spp (samplecnt_t len) +{ + double available_width = frame->get().width(); + spp = floor (len / available_width); + + for (auto & wave : waves) { + wave->set_samples_per_pixel (spp); + } +} + void AudioClipEditor::set_wave_heights (int h) { @@ -129,9 +159,6 @@ AudioClipEditor::set_wave_heights (int h) for (auto & wave : waves) { wave->set_height (ht); wave->set_y_position (n * ht); - wave->set_samples_per_pixel (256); - wave->set_show_zero_line (false); - wave->set_clip_level (1.0); ++n; } } diff --git a/gtk2_ardour/audio_clip_editor.h b/gtk2_ardour/audio_clip_editor.h index cda85e44ec..74c24db3c0 100644 --- a/gtk2_ardour/audio_clip_editor.h +++ b/gtk2_ardour/audio_clip_editor.h @@ -27,6 +27,7 @@ #include #include "ardour/ardour.h" +#include "ardour/types.h" #include "ardour/session_handle.h" #include "gtkmm2ext/cairo_packer.h" @@ -71,12 +72,13 @@ class AudioClipEditor : public ArdourCanvas::GtkCanvas private: ArdourCanvas::Rectangle* frame; - bool event_handler (GdkEvent* ev); - std::vector waves; + double spp; + bool event_handler (GdkEvent* ev); void drop_waves (); void set_wave_heights (int); + void set_wave_spp (ARDOUR::samplecnt_t); void set_waveform_colors (); };