audio clip editor: draw entire source file(s), not just region

This commit is contained in:
Paul Davis 2021-12-10 08:54:38 -07:00
parent 5ada2b7ce1
commit 3bbe54f07a
2 changed files with 37 additions and 8 deletions

View File

@ -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<AudioRegion> 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<Region> wr = RegionFactory::get_whole_region_for_source (r->source (n));
if (!wr) {
continue;
}
boost::shared_ptr<AudioRegion> war = boost::dynamic_pointer_cast<AudioRegion> (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;
}
}

View File

@ -27,6 +27,7 @@
#include <gtkmm/table.h>
#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<ArdourWaveView::WaveView *> 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 ();
};