triggerbox: continued evolution, and new test sample paths

This commit is contained in:
Paul Davis 2021-07-20 23:04:11 -06:00
parent f7c6d17ee3
commit 043544c059
2 changed files with 86 additions and 25 deletions

View file

@ -43,10 +43,10 @@ class TriggerBox;
class LIBARDOUR_API Trigger { class LIBARDOUR_API Trigger {
public: public:
Trigger (boost::shared_ptr<Region>); Trigger (size_t index, boost::shared_ptr<Region>);
virtual ~Trigger() {} virtual ~Trigger() {}
virtual void bang (TriggerBox&, Temporal::Beats const &, samplepos_t) = 0; virtual void bang (TriggerBox&) = 0;
virtual void unbang (TriggerBox&, Temporal::Beats const &, samplepos_t) = 0; virtual void unbang (TriggerBox&, Temporal::Beats const &, samplepos_t) = 0;
bool running() const { return _running; } bool running() const { return _running; }
@ -82,6 +82,9 @@ class LIBARDOUR_API Trigger {
void set_quantization (Temporal::Beats const &); void set_quantization (Temporal::Beats const &);
bool stop_requested() const { return _stop_requested; } bool stop_requested() const { return _stop_requested; }
virtual void stop();
size_t index() const { return _index; }
/* Managed by TriggerBox */ /* Managed by TriggerBox */
samplepos_t fire_samples; samplepos_t fire_samples;
@ -90,6 +93,7 @@ class LIBARDOUR_API Trigger {
protected: protected:
bool _running; bool _running;
bool _stop_requested; bool _stop_requested;
size_t _index;
LaunchStyle _launch_style; LaunchStyle _launch_style;
FollowAction _follow_action; FollowAction _follow_action;
boost::shared_ptr<Region> _region; boost::shared_ptr<Region> _region;
@ -100,10 +104,10 @@ class LIBARDOUR_API Trigger {
class LIBARDOUR_API AudioTrigger : public Trigger { class LIBARDOUR_API AudioTrigger : public Trigger {
public: public:
AudioTrigger (boost::shared_ptr<AudioRegion>); AudioTrigger (size_t index, boost::shared_ptr<AudioRegion>);
~AudioTrigger (); ~AudioTrigger ();
void bang (TriggerBox&, Temporal::Beats const & , samplepos_t); void bang (TriggerBox&);
void unbang (TriggerBox&, Temporal::Beats const & , samplepos_t); void unbang (TriggerBox&, Temporal::Beats const & , samplepos_t);
Sample* run (uint32_t channel, pframes_t& nframes, bool& need_butler); Sample* run (uint32_t channel, pframes_t& nframes, bool& need_butler);
@ -117,6 +121,7 @@ class LIBARDOUR_API AudioTrigger : public Trigger {
void drop_data (); void drop_data ();
int load_data (boost::shared_ptr<AudioRegion>); int load_data (boost::shared_ptr<AudioRegion>);
void retrigger ();
}; };
class LIBARDOUR_API TriggerBox : public Processor class LIBARDOUR_API TriggerBox : public Processor

View file

@ -31,6 +31,10 @@ TriggerBox::TriggerBox (Session& s)
midi_trigger_map.insert (midi_trigger_map.end(), std::make_pair (uint8_t (63), 3)); midi_trigger_map.insert (midi_trigger_map.end(), std::make_pair (uint8_t (63), 3));
midi_trigger_map.insert (midi_trigger_map.end(), std::make_pair (uint8_t (64), 4)); midi_trigger_map.insert (midi_trigger_map.end(), std::make_pair (uint8_t (64), 4));
midi_trigger_map.insert (midi_trigger_map.end(), std::make_pair (uint8_t (65), 5)); midi_trigger_map.insert (midi_trigger_map.end(), std::make_pair (uint8_t (65), 5));
midi_trigger_map.insert (midi_trigger_map.end(), std::make_pair (uint8_t (66), 6));
midi_trigger_map.insert (midi_trigger_map.end(), std::make_pair (uint8_t (67), 7));
midi_trigger_map.insert (midi_trigger_map.end(), std::make_pair (uint8_t (68), 8));
midi_trigger_map.insert (midi_trigger_map.end(), std::make_pair (uint8_t (69), 9));
load_some_samples (); load_some_samples ();
@ -42,19 +46,23 @@ TriggerBox::load_some_samples ()
/* XXX TESTING ONLY */ /* XXX TESTING ONLY */
char const * paths[] = { char const * paths[] = {
"RAZOR_6-pack_Disco_Bell.wav", "AS_AP_Perc_Loop_01_125bpm.wav",
"RAZOR_6-pack_Percuvox.wav", "AS_AP_Perc_Loop_05_125bpm.wav",
"RAZOR_6-pack_GentleWobbler_Up+Down.wav", "AS_AP_Perc_Loop_09_125bpm.wav",
"RAZOR_6-pack_Rolling_Triplets.wav", "AS_AP_Perc_Loop_02_125bpm.wav",
"RAZOR_6-pack_Leaky_Chamber.wav", "AS_AP_Perc_Loop_06_125bpm.wav",
"RAZOR_6-pack_Rubber_Wobbler.wav", "AS_AP_Perc_Loop_10_125bpm.wav",
"AS_AP_Perc_Loop_03_125bpm.wav",
"AS_AP_Perc_Loop_07_125bpm.wav",
"AS_AP_Perc_Loop_04_125bpm.wav",
"AS_AP_Perc_Loop_08_125bpm.wav",
0 0
}; };
try { try {
for (size_t n = 0; paths[n]; ++n) { for (size_t n = 0; paths[n]; ++n) {
string dir = "/usr/local/music/samples/Razor_6-pack_RawLoops_128BPM/"; string dir = "/usr/local/music/samples/Loops\ \(WAV\)/ASHRAM\ Afro\ Percussion\ Loops/";
string path = dir + paths[n]; string path = dir + paths[n];
@ -83,7 +91,7 @@ TriggerBox::load_some_samples ()
boost::shared_ptr<Region> the_region (RegionFactory::create (src_list, plist, false)); boost::shared_ptr<Region> the_region (RegionFactory::create (src_list, plist, false));
all_triggers[n] = new AudioTrigger (boost::dynamic_pointer_cast<AudioRegion> (the_region)); all_triggers[n] = new AudioTrigger (n, boost::dynamic_pointer_cast<AudioRegion> (the_region));
} }
} catch (std::exception& e) { } catch (std::exception& e) {
cerr << "loading samples failed: " << e.what() << endl; cerr << "loading samples failed: " << e.what() << endl;
@ -202,8 +210,12 @@ TriggerBox::process_midi_trigger_requests (BufferSet& bufs)
if ((*ev).is_note_on()) { if ((*ev).is_note_on()) {
if (!t->running() && find (pending_on_triggers.begin(), pending_on_triggers.end(), t) == pending_on_triggers.end()) { if (!t->running()) {
pending_on_triggers.push_back (t); if (find (pending_on_triggers.begin(), pending_on_triggers.end(), t) == pending_on_triggers.end()) {
pending_on_triggers.push_back (t);
}
} else {
t->bang (*this);
} }
if (!_session.transport_state_rolling()) { if (!_session.transport_state_rolling()) {
@ -284,7 +296,7 @@ TriggerBox::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
if (trigger->stop_requested()) { if (trigger->stop_requested()) {
trigger_samples = nframes - (trigger->fire_samples - start_sample); trigger_samples = nframes - (trigger->fire_samples - start_sample);
} else if (!trigger->running()) { } else if (!trigger->running()) {
trigger->bang (*this, trigger->fire_beats, trigger->fire_samples); trigger->bang (*this);
dest_offset = std::max (samplepos_t (0), trigger->fire_samples - start_sample); dest_offset = std::max (samplepos_t (0), trigger->fire_samples - start_sample);
trigger_samples = nframes - dest_offset; trigger_samples = nframes - dest_offset;
} }
@ -339,10 +351,11 @@ TriggerBox::set_state (const XMLNode&, int version)
/*--------------------*/ /*--------------------*/
Trigger::Trigger (boost::shared_ptr<Region> r) Trigger::Trigger (size_t n, boost::shared_ptr<Region> r)
: _running (false) : _running (false)
, _stop_requested (false) , _stop_requested (false)
, _launch_style (Gate) , _index (n)
, _launch_style (Loop)
, _follow_action (Stop) , _follow_action (Stop)
, _region (r) , _region (r)
{ {
@ -376,10 +389,16 @@ Trigger::quantization () const
return _quantization; return _quantization;
} }
void
Trigger::stop ()
{
_stop_requested = true;
}
/*--------------------*/ /*--------------------*/
AudioTrigger::AudioTrigger (boost::shared_ptr<AudioRegion> r) AudioTrigger::AudioTrigger (size_t n, boost::shared_ptr<AudioRegion> r)
: Trigger (r) : Trigger (n, r)
, data (0) , data (0)
, length (0) , length (0)
{ {
@ -448,15 +467,37 @@ AudioTrigger::load_data (boost::shared_ptr<AudioRegion> ar)
} }
void void
AudioTrigger::bang (TriggerBox& /*proc*/, Temporal::Beats const &, samplepos_t) AudioTrigger::retrigger ()
{ {
/* user triggered this, and we need to get things set up for calls to
* run()
*/
for (std::vector<samplecnt_t>::iterator ri = read_index.begin(); ri != read_index.end(); ++ri) { for (std::vector<samplecnt_t>::iterator ri = read_index.begin(); ri != read_index.end(); ++ri) {
(*ri) = 0; (*ri) = 0;
} }
}
void
AudioTrigger::bang (TriggerBox& /*proc*/)
{
/* user "hit" the trigger in a way that means "start" */
switch (_launch_style) {
case Loop:
retrigger ();
break;
case Gate:
retrigger ();
break;
case Toggle:
if (_running) {
_stop_requested = true;
} else {
retrigger ();
}
break;
case Repeat:
retrigger ();
break;
}
_running = true; _running = true;
} }
@ -464,7 +505,22 @@ AudioTrigger::bang (TriggerBox& /*proc*/, Temporal::Beats const &, samplepos_t)
void void
AudioTrigger::unbang (TriggerBox& /*proc*/, Temporal::Beats const &, samplepos_t) AudioTrigger::unbang (TriggerBox& /*proc*/, Temporal::Beats const &, samplepos_t)
{ {
_stop_requested = true; /* user "hit" the trigger in a way that means "stop" */
switch (_launch_style) {
case Loop:
/* do nothing, wait for next "start" */
break;
case Gate:
_stop_requested = true;
break;
case Toggle:
/* do nothing ... wait for next "start" */
break;
case Repeat:
_stop_requested = true;
break;
}
} }
Sample* Sample*