triggerbox: consolidate position-as-fraction code
Both trigger types now use a process_index and final_processed_sample value to compute their current position-as-fraction
This commit is contained in:
parent
5af43793d3
commit
374fa48fad
|
@ -254,10 +254,10 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
|
|||
virtual void set_length (timecnt_t const &) = 0;
|
||||
virtual void reload (BufferSet&, void*) = 0;
|
||||
virtual void io_change () {}
|
||||
virtual timepos_t current_pos() const = 0;
|
||||
virtual void set_legato_offset (timepos_t const & offset) = 0;
|
||||
|
||||
virtual double position_as_fraction() const = 0;
|
||||
timepos_t current_pos() const;
|
||||
double position_as_fraction() const;
|
||||
|
||||
Temporal::BBT_Time compute_start (Temporal::TempoMap::SharedPtr const &, samplepos_t start, samplepos_t end, Temporal::BBT_Offset const & q, samplepos_t& start_samples, bool& will_start);
|
||||
virtual timepos_t compute_end (Temporal::TempoMap::SharedPtr const &, Temporal::BBT_Time const &, samplepos_t) = 0;
|
||||
|
@ -365,6 +365,8 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
|
|||
};
|
||||
|
||||
boost::shared_ptr<Region> _region;
|
||||
samplecnt_t process_index;
|
||||
samplepos_t final_processed_sample; /* where we stop playing, in process time, compare with process_index */
|
||||
UIState ui_state;
|
||||
TriggerBox& _box;
|
||||
UIRequests _requests;
|
||||
|
@ -407,7 +409,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
|
|||
|
||||
void when_stopped_during_run (BufferSet& bufs, pframes_t dest_offset);
|
||||
void set_region_internal (boost::shared_ptr<Region>);
|
||||
virtual void retrigger() = 0;
|
||||
virtual void retrigger();
|
||||
virtual void _startup (BufferSet&, pframes_t dest_offset, Temporal::BBT_Offset const &);
|
||||
|
||||
bool internal_use_follow_length() const;
|
||||
|
@ -441,7 +443,6 @@ class LIBARDOUR_API AudioTrigger : public Trigger {
|
|||
void set_start (timepos_t const &);
|
||||
void set_end (timepos_t const &);
|
||||
void set_legato_offset (timepos_t const &);
|
||||
timepos_t current_pos() const;
|
||||
void set_length (timecnt_t const &);
|
||||
timepos_t start_offset () const; /* offset from start of data */
|
||||
timepos_t current_length() const; /* offset from start of data */
|
||||
|
@ -450,8 +451,6 @@ class LIBARDOUR_API AudioTrigger : public Trigger {
|
|||
void io_change ();
|
||||
bool probably_oneshot () const;
|
||||
|
||||
double position_as_fraction() const;
|
||||
|
||||
int set_region_in_worker_thread (boost::shared_ptr<Region>);
|
||||
void jump_start ();
|
||||
void jump_stop (BufferSet& bufs, pframes_t dest_offset);
|
||||
|
@ -485,9 +484,7 @@ class LIBARDOUR_API AudioTrigger : public Trigger {
|
|||
/* computed during run */
|
||||
|
||||
samplecnt_t read_index;
|
||||
samplecnt_t process_index;
|
||||
samplepos_t last_readable_sample; /* where the data runs out, relative to the start of the data, compare with read_index */
|
||||
samplepos_t final_processed_sample; /* where we stop playing, in process time, compare with process_index */
|
||||
samplepos_t _legato_offset;
|
||||
samplecnt_t retrieved;
|
||||
samplecnt_t got_stretcher_padding;
|
||||
|
@ -519,7 +516,6 @@ class LIBARDOUR_API MIDITrigger : public Trigger {
|
|||
void set_start (timepos_t const &);
|
||||
void set_end (timepos_t const &);
|
||||
void set_legato_offset (timepos_t const &);
|
||||
timepos_t current_pos() const;
|
||||
void set_length (timecnt_t const &);
|
||||
timepos_t start_offset () const;
|
||||
timepos_t end() const; /* offset from start of data */
|
||||
|
@ -528,8 +524,6 @@ class LIBARDOUR_API MIDITrigger : public Trigger {
|
|||
void reload (BufferSet&, void*);
|
||||
bool probably_oneshot () const;
|
||||
|
||||
double position_as_fraction() const;
|
||||
|
||||
int set_region_in_worker_thread (boost::shared_ptr<Region>);
|
||||
void jump_start ();
|
||||
void shutdown (BufferSet& bufs, pframes_t dest_offset);
|
||||
|
|
|
@ -168,6 +168,8 @@ Trigger::Trigger (uint32_t n, TriggerBox& b)
|
|||
, _stretch_mode (Properties::stretch_mode, Trigger::Crisp)
|
||||
, _name (Properties::name, "")
|
||||
, _color (Properties::color, 0xBEBEBEFF)
|
||||
, process_index (0)
|
||||
, final_processed_sample (0)
|
||||
, _box (b)
|
||||
, _state (Stopped)
|
||||
, _bang (0)
|
||||
|
@ -575,6 +577,28 @@ Trigger::set_region_internal (boost::shared_ptr<Region> r)
|
|||
cerr << index() << " aka " << this << " region set to " << r << endl;
|
||||
}
|
||||
|
||||
timepos_t
|
||||
Trigger::current_pos() const
|
||||
{
|
||||
return timepos_t (process_index);
|
||||
}
|
||||
|
||||
double
|
||||
Trigger::position_as_fraction () const
|
||||
{
|
||||
if (!active()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return process_index / (double) final_processed_sample;
|
||||
}
|
||||
|
||||
void
|
||||
Trigger::retrigger ()
|
||||
{
|
||||
process_index = 0;
|
||||
}
|
||||
|
||||
void
|
||||
Trigger::request_stop ()
|
||||
{
|
||||
|
@ -1010,9 +1034,7 @@ AudioTrigger::AudioTrigger (uint32_t n, TriggerBox& b)
|
|||
, _stretcher (0)
|
||||
, _start_offset (0)
|
||||
, read_index (0)
|
||||
, process_index (0)
|
||||
, last_readable_sample (0)
|
||||
, final_processed_sample (0)
|
||||
, _legato_offset (0)
|
||||
, retrieved (0)
|
||||
, got_stretcher_padding (false)
|
||||
|
@ -1113,16 +1135,6 @@ AudioTrigger::jump_stop (BufferSet& bufs, pframes_t dest_offset)
|
|||
retrigger ();
|
||||
}
|
||||
|
||||
double
|
||||
AudioTrigger::position_as_fraction () const
|
||||
{
|
||||
if (!active()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return process_index / (double) (expected_end_sample - transition_samples);
|
||||
}
|
||||
|
||||
XMLNode&
|
||||
AudioTrigger::get_state (void)
|
||||
{
|
||||
|
@ -1174,12 +1186,6 @@ AudioTrigger::start_offset () const
|
|||
return timepos_t (_start_offset);
|
||||
}
|
||||
|
||||
timepos_t
|
||||
AudioTrigger::current_pos() const
|
||||
{
|
||||
return timepos_t (process_index);
|
||||
}
|
||||
|
||||
void
|
||||
AudioTrigger::start_and_roll_to (samplepos_t start_pos, samplepos_t end_position)
|
||||
{
|
||||
|
@ -1612,11 +1618,12 @@ AudioTrigger::load_data (boost::shared_ptr<AudioRegion> ar)
|
|||
void
|
||||
AudioTrigger::retrigger ()
|
||||
{
|
||||
Trigger::retrigger ();
|
||||
|
||||
update_properties ();
|
||||
reset_stretcher ();
|
||||
|
||||
read_index = _start_offset + _legato_offset;
|
||||
process_index = 0;
|
||||
retrieved = 0;
|
||||
_legato_offset = 0; /* used one time only */
|
||||
|
||||
|
@ -2116,7 +2123,11 @@ MIDITrigger::compute_end (Temporal::TempoMap::SharedPtr const & tmap, Temporal::
|
|||
final_beat = len.beats ();
|
||||
}
|
||||
|
||||
return timepos_t (final_beat);
|
||||
timepos_t e (final_beat);
|
||||
|
||||
final_processed_sample = e.samples() - transition_samples;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
SegmentDescriptor
|
||||
|
@ -2194,21 +2205,6 @@ MIDITrigger::jump_stop (BufferSet& bufs, pframes_t dest_offset)
|
|||
retrigger ();
|
||||
}
|
||||
|
||||
double
|
||||
MIDITrigger::position_as_fraction () const
|
||||
{
|
||||
if (!active()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
Temporal::DoubleableBeats db (last_event_beats);
|
||||
|
||||
double dl = db.to_double ();
|
||||
double dr = data_length.to_double ();
|
||||
|
||||
return dl / dr;
|
||||
}
|
||||
|
||||
XMLNode&
|
||||
MIDITrigger::get_state (void)
|
||||
{
|
||||
|
@ -2336,12 +2332,6 @@ MIDITrigger::start_offset () const
|
|||
return timepos_t (m.to_quarters (_start_offset));
|
||||
}
|
||||
|
||||
timepos_t
|
||||
MIDITrigger::current_pos() const
|
||||
{
|
||||
return timepos_t (last_event_beats);
|
||||
}
|
||||
|
||||
void
|
||||
MIDITrigger::set_length (timecnt_t const & newlen)
|
||||
{
|
||||
|
@ -2391,6 +2381,8 @@ MIDITrigger::set_region_in_worker_thread (boost::shared_ptr<Region> r)
|
|||
void
|
||||
MIDITrigger::retrigger ()
|
||||
{
|
||||
Trigger::retrigger ();
|
||||
|
||||
update_properties ();
|
||||
|
||||
/* XXX need to deal with bar offsets */
|
||||
|
@ -2575,6 +2567,8 @@ MIDITrigger::midi_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t en
|
|||
when_stopped_during_run (bufs, dest_offset + covered_frames);
|
||||
}
|
||||
|
||||
process_index += covered_frames;
|
||||
|
||||
return covered_frames;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue