Ardour  9.2-129-gdf5e1050bd
triggerbox.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include <pthread.h>
22 
23 #include <atomic>
24 #include <map>
25 #include <memory>
26 #include <vector>
27 #include <string>
28 
29 #include "pbd/crossthread.h"
30 #include "pbd/mutex.h"
31 #include "pbd/pcg_rand.h"
32 #include "pbd/pool.h"
33 #include "pbd/properties.h"
34 #include "pbd/ringbuffer.h"
35 #include "pbd/rwlock.h"
36 #include "pbd/stateful.h"
37 
38 #include "midi++/types.h"
39 
40 #include "temporal/beats.h"
41 #include "temporal/bbt_time.h"
42 #include "temporal/tempo.h"
43 
44 #include "evoral/PatchChange.h"
45 #include "evoral/SMF.h"
46 
48 #include "ardour/midi_model.h"
50 #include "ardour/processor.h"
51 #include "ardour/rt_midibuffer.h"
53 #include "ardour/types.h"
54 #include "ardour/types_convert.h"
55 
57 
58 class XMLNode;
59 
60 namespace RubberBand {
61  class RubberBandStretcher;
62 }
63 
64 namespace MIDI {
65  class Parser;
66 }
67 
68 namespace ARDOUR {
69 
70 class Session;
71 class AudioRegion;
72 class MidiRegion;
73 class TriggerBox;
74 struct SlotArmInfo;
75 class SideChain;
76 class MidiPort;
77 
78 typedef uint32_t color_t;
79 
80 LIBARDOUR_API std::string cue_marker_name (int32_t);
81 
82 class Trigger;
83 
84 typedef std::shared_ptr<Trigger> TriggerPtr;
86 
88  public:
89  enum State {
90  /* This is the initial state for a Trigger, and means that it is not
91  * doing anything at all
92  */
94  /* A Trigger in this state has been chosen by its parent TriggerBox
95  * (e.g. because of a bang() call that put it in the queue), a Trigger in
96  * this state is waiting for the next occurence of its quantization to
97  * occur before transitioning to Running
98  */
100  /* a Trigger in this state is going to deliver data during calls
101  * to its ::run() method.
102  */
104  /* a Trigger in this state was running, has been re-triggered e.g. by a
105  * ::bang() call with LaunchStyle set to Repeat, and is waiting for the
106  * next occurence of its quantization to occur before transitioning
107  * back to Running.
108  */
110  /* a Trigger in this state is delivering data during calls to ::run(), but
111  * is waiting for the next occurence of its quantization to occur when it will
112  * transition to Stopping and then Stopped.
113  */
115  /* a Trigger in this state is delivering data during calls to ::run(), but
116  * is waiting for the next occurence of another Trigger's quantization to occur when it will
117  * transition to Stopping and then Stopped (and be followed by
118  * the other Trigger.
119  */
121  /* a Trigger in this state was Running but noticed that it should stop
122  * during the current call to ::run(). By the end of that call, it will
123  * have transitioned to Stopped.
124  */
126  };
127 
128  enum LaunchStyle {
129  OneShot, /* mouse down/NoteOn starts; mouse up/NoteOff ignored */
130  ReTrigger, /* mouse down/NoteOn starts or retriggers; mouse up/NoteOff */
131  Gate, /* runs till mouse up/note off then to next quantization */
132  Toggle, /* runs till next mouse down/NoteOn */
133  Repeat, /* plays only quantization extent until mouse up/note off */
134  };
135 
136  enum StretchMode { /* currently mapped to the matching RubberBand::RubberBandStretcher::Option */
140  };
141 
142  Trigger (uint32_t index, TriggerBox&);
143  virtual ~Trigger() {}
144 
145  static void make_property_quarks ();
146 
147  protected:
148  /* properties controllable by the user */
149 
166 
167  /* Properties that are not CAS-updated at retrigger */
168 
171 
172  public:
173  /* this is positioned here so that we can easily keep it in sync
174  with the properties list above.
175  */
176  struct UIState {
177  std::atomic<unsigned int> generation; /* used for CAS */
178 
183  uint32_t follow_count = 1;
187  bool use_follow_length = false;
188  bool legato = false;
189  gain_t gain = 1.0;
190  float velocity_effect = 0;
191  bool stretchable = true;
192  bool cue_isolated = false;
193  bool allow_patch_changes = true;
195 
198 
199  std::string name = "";
200  color_t color = 0xBEBEBEFF;
201  double tempo = 0; //unset
202 
203  UIState() : generation (0) {}
204 
205  UIState& operator= (UIState const & other) {
206 
207  /* we do not copy generation */
208 
209  generation = 0;
210 
211  launch_style = other.launch_style;
215  follow_count = other.follow_count;
216  quantization = other.quantization;
220  legato = other.legato;
221  gain = other.gain;
223  stretchable = other.stretchable;
224  cue_isolated = other.cue_isolated;
226  stretch_mode = other.stretch_mode;
228 
229  for (int i = 0; i<16; i++) {
230  if (other.patch_change[i].is_set()) {
231  patch_change[i] = other.patch_change[i];
232  }
233  }
234 
235  name = other.name;
236  color = other.color;
237  tempo = other.tempo;
238 
239  return *this;
240  }
241  };
242 
243 #define TRIGGERBOX_PROPERTY_DECL(name,type) void set_ ## name (type); type name () const;
244 #define TRIGGERBOX_PROPERTY_DECL_CONST_REF(name,type) void set_ ## name (type const &); type name () const
245 
264 
265 #undef TRIGGERBOX_PROPERTY_DECL
266 #undef TRIGGERBOX_PROPERTY_DECL_CONST_REF
267 
268  /* Calling ::bang() will cause this Trigger to be placed in its owning
269  TriggerBox's queue.
270  */
271  void bang (float velocity = 1.0f);
272 
273  /* Calling ::unbang() is equivalent to a mouse-up or note-off
274  ... it MIGHT cause a clip to stop, but more likely has no effect, depending on the slot's launch-style.
275  */
276  void unbang ();
277 
278  /* Calling ::request_stop() to stop a Trigger at the earliest possible
279  * opportunity, rather than at the next quantization point.
280  */
281  void request_stop ();
282 
283  /* Call ::stop_quantized() to stop a Trigger at the next quantization point.
284  */
285  void stop_quantized ();
286 
287  virtual void tempo_map_changed() {}
288 
289  virtual pframes_t run (BufferSet&, samplepos_t start_sample, samplepos_t end_sample,
290  Temporal::Beats const & start, Temporal::Beats const & end,
291  pframes_t nframes, pframes_t offset, double bpm, pframes_t& quantize_offset) = 0;
292  virtual void io_change () {}
293  virtual void set_legato_offset (timepos_t const & offset) = 0;
294 
296  double position_as_fraction() const;
297 
298  virtual void captured (SlotArmInfo&) {}
300  _arm (duration);
301  }
302  virtual void disarm ();
303  bool armed() const { return _armed; }
305  static PBD::Signal<void(Trigger const *)> TriggerArmChanged;
306 
307 
310  virtual void start_and_roll_to (samplepos_t start, samplepos_t position, uint32_t cnt) = 0;
311 
312  /* because follow actions involve probability is it easier to code the will-not-follow case */
313 
314  bool will_not_follow() const;
315  bool will_follow() const { return !will_not_follow(); }
316 
317  /* assumes that this is currently playing but does not enforce it */
318  bool cue_launched() const { return _cue_launched; }
319 
320  virtual bool probably_oneshot () const = 0;
321 
322  void process_state_requests (BufferSet& bufs, pframes_t dest_offset);
323 
324  bool active() const { return _state >= Running; }
325  State state() const { return _state; }
326 
327  void set_region (std::shared_ptr<Region>, bool use_thread = true);
328  void clear_region ();
329  virtual int set_region_in_worker_thread (std::shared_ptr<Region>) = 0;
330  virtual int set_region_in_worker_thread_from_capture (std::shared_ptr<Region>) = 0;
331  std::shared_ptr<Region> the_region() const { return _region; }
332  virtual bool playable() const = 0;
333 
334  uint32_t index() const { return _index; }
335 
336  /* Managed by TriggerBox, these record the time that the trigger is
337  * scheduled to start or stop at. Computed in
338  * Trigger::maybe_compute_next_transition().
339  */
343 
344  XMLNode& get_state () const;
345  int set_state (const XMLNode&, int version);
346 
347  void maybe_compute_next_transition (samplepos_t start_sample, Temporal::Beats const & start, Temporal::Beats const & end, pframes_t& nframes, pframes_t& dest_offset);
348 
349 
351  Temporal::BBT_Argument& t_bbt, Temporal::Beats& t_beats, samplepos_t& t_samples,
352  Temporal::TempoMap::SharedPtr const & tmap, Temporal::BBT_Offset const & q);
353 
355  Temporal::BBT_Argument& t_bbt, Temporal::Beats& t_beats, samplepos_t& t_samples,
356  Temporal::TempoMap::SharedPtr const & tmap);
357 
358 
359  template<typename TriggerType>
360  void start_and_roll_to (samplepos_t start_pos, samplepos_t end_position, TriggerType& trigger,
361  pframes_t (TriggerType::*run_method) (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample,
362  Temporal::Beats const & start_beats, Temporal::Beats const & end_beats,
363  pframes_t nframes, pframes_t dest_offset, double bpm, pframes_t&), uint32_t cnt);
364  void set_next_trigger (int n);
365  int next_trigger() const { return _next_trigger; }
366 
367  /* any non-zero value will work for the default argument, and means
368  "use your own launch quantization". BBT_Offset (0, 0, 0) means what
369  it says: start immediately
370  */
371  void startup (BufferSet&, pframes_t dest_offset, Temporal::BBT_Offset const & start_quantization = Temporal::BBT_Offset (9, 3,0));
372  void startup_from_ffwd (BufferSet&, uint32_t loop_cnt);
374  virtual void shutdown (BufferSet& bufs, pframes_t dest_offset);
375  virtual void jump_start ();
376  virtual void jump_stop (BufferSet& bufs, pframes_t dest_offset);
377  void begin_stop (bool explicit_stop = false);
379 
380  bool explicitly_stopped() const { return _explicitly_stopped; }
381  void set_scene_switch (bool yn);
382 
383  uint32_t loop_count() const { return _loop_cnt; }
384 
385  void set_ui (void*);
386  void* ui () const { return _ui; }
387 
388  TriggerBox& box() const { return _box; }
389  std::shared_ptr<TriggerBox> boxptr() const;
390 
391  double estimated_tempo() const { return _estimated_tempo; }
392 
393  /* the following functions deal with audio- or midi-specific SegmentDescriptor properties, provided as virtuals so we don't have to do lots of dynamic_casting */
394  /* segment_tempo is currently a no-op for MIDI, but may be implemented later */
395  virtual double segment_tempo() const = 0;
396  virtual void set_segment_tempo (double t) = 0;
397 
398  /* used_channels is a no-op for audio */
401 
402  /* patch changes are a no-op for audio */
405  virtual void unset_patch_change (uint8_t channel) {}
406  virtual void unset_all_patch_changes () {}
407  virtual bool patch_change_set (uint8_t channel) const { return false; }
408 
409  virtual void setup_stretcher () = 0;
410 
411  Temporal::Meter meter() const { return _meter; }
412 
413  void set_velocity_gain (gain_t g) {_pending_velocity_gain=g;}
414 
417 
419 
421 
423 
424  static void request_trigger_delete (Trigger* t);
425 
426  /* these operations are provided to get/set all the "user visible" trigger properties at once */
427  /* examples: drag+dropping from slot to slot, or "Range->Bounce to Slot", where a single operation sets many */
428  void get_ui_state (UIState &state) const;
429  void set_ui_state (UIState &state);
430 
431  virtual void check_edit_swap (timepos_t const & time, bool playing, BufferSet& bufs) = 0;
432 
434 
436  virtual void bounds_changed (Temporal::timepos_t const & start, Temporal::timepos_t const & end, Temporal::timecnt_t const & len);
437 
438  protected:
439  struct UIRequests {
440  std::atomic<bool> stop;
441  UIRequests() : stop (false) {}
442  };
443 
444  std::shared_ptr<Region> _region;
446  samplepos_t final_process_index; /* where we stop playing, in process time, compare with process_index */
451  bool _playout;
452  std::atomic<int> _bang;
453  std::atomic<int> _unbang;
454  uint32_t _index;
456  uint32_t _loop_cnt; /* how many times in a row has this played */
457  void* _ui;
463  bool _armed;
464 
465  /* these are only used by midi triggers but the ui_state API needs them */
468  std::vector<int> _channel_map;
469 
471 
472 
473  /* computed from data */
474 
475  double _estimated_tempo; //TODO: this should come from the MIDI file
476  double _segment_tempo; //TODO: this will likely get stored in the SegmentDescriptor for audio triggers
477 
478  /* basic process is :
479  1) when a file is loaded, we infer its bpm either by minibpm's estimate, a flag in the filename, metadata (TBD) or other means
480  2) we assume the clip must have an integer number of beats in it (simplest case is a one-bar loop with 4 beats in it)
481  3) ...so we round to the nearest beat length, and set the tempo to *exactly* fit the sample-length into the assumed beat-length
482  4) the user may recognize a problem: "this was a 3/4 beat, which was rounded to 4 beats but it should have been 3"
483  5) if the user changes the beat-length, then the tempo is recalculated for use during stretching
484  6) someday, we will also allow the sample start and length to be adjusted in a trimmer, and that will also adjust the tempo
485  7) in all cases the user should be in final control; but our "internal" value for stretching are just sample-start and BPM, end of story
486  */
487  double _beatcnt;
489 
493  std::atomic<Trigger*> _pending;
494  std::atomic<unsigned int> last_property_generation;
496 
497  void when_stopped_during_run (BufferSet& bufs, pframes_t dest_offset);
498  void set_region_internal (std::shared_ptr<Region>);
499  virtual void retrigger();
500  virtual void _startup (BufferSet&, pframes_t dest_offset, Temporal::BBT_Offset const &);
501 
504 
505  virtual void _arm (Temporal::BBT_Offset const &);
506 
507  struct PendingSwap {
513 
514  virtual ~PendingSwap() {}
515  };
516 
517  std::atomic<PendingSwap*> pending_swap;
518  std::atomic<PendingSwap*> old_pending_swap;
519 
520  virtual int load_pending_data (PendingSwap&) = 0;
521  virtual PendingSwap* pending_factory() const = 0;
522 };
523 
525  public:
526  AudioTrigger (uint32_t index, TriggerBox&);
528 
529  template<bool actually_run> pframes_t audio_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample,
530  Temporal::Beats const & start, Temporal::Beats const & end,
531  pframes_t nframes, pframes_t dest_offset, double bpm, pframes_t& quantize_offset);
532 
533  pframes_t run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, Temporal::Beats const & start, Temporal::Beats const & end, pframes_t nframes, pframes_t dest_offset, double bpm, pframes_t& quantize_offset) {
534  return audio_run<true> (bufs, start_sample, end_sample, start, end, nframes, dest_offset, bpm, quantize_offset);
535  }
536 
537  bool playable() const { return data.length || _region; }
538 
539  StretchMode stretch_mode() const { return _stretch_mode; }
541 
542  double segment_tempo() const { return _segment_tempo; }
543  void set_segment_tempo (double t);
544 
545  double segment_beatcnt () { return _beatcnt; }
546  void set_segment_beatcnt (double count);
547 
548  void set_legato_offset (timepos_t const &);
549  void set_length (timecnt_t const &);
550  void io_change ();
551  bool probably_oneshot () const;
552 
554 
555  int set_region_in_worker_thread (std::shared_ptr<Region>);
556  int set_region_in_worker_thread_from_capture (std::shared_ptr<Region>);
557  void jump_start ();
558  void jump_stop (BufferSet& bufs, pframes_t dest_offset);
559 
560  XMLNode& get_state () const;
561  int set_state (const XMLNode&, int version);
562 
563  RubberBand::RubberBandStretcher* stretcher() { return (_stretcher); }
564 
568 
569  bool stretching () const;
570  uint32_t channels () const { return data.size(); }
571 
572  RubberBand::RubberBandStretcher* alloc_stretcher () const;
573 
574  struct AudioData : std::vector<Sample*> {
577 
578  AudioData () : length (0), capacity (0) {}
580  AudioData& operator= (AudioData& other); /* really move semantics */
581 
582  samplecnt_t append (Sample const * src, samplecnt_t cnt, uint32_t chan);
583  void alloc (samplecnt_t cnt, uint32_t nchans);
584  void reset () { length = 0; }
585  void drop ();
586  };
587 
588 
589  Sample const * audio_data (size_t n) const;
590  size_t data_length() const { return data.length; }
591 
592  struct AudioPendingSwap : public PendingSwap {
594 
597  };
598 
599  void check_edit_swap (timepos_t const &, bool playing, BufferSet&);
600 
601  protected:
602  void retrigger ();
605 
606  private:
608  RubberBand::RubberBandStretcher* _stretcher;
609 
610  /* computed during run */
611 
613  samplepos_t last_readable_sample; /* where the data runs out, relative to the start of the data, compare with read_index */
619 
620  virtual void setup_stretcher ();
621 
623  int load_data (std::shared_ptr<AudioRegion>, AudioData&);
624  void estimate_tempo ();
626  void _startup (BufferSet&, pframes_t dest_offset, Temporal::BBT_Offset const &);
627  int set_region_in_worker_thread_internal (std::shared_ptr<Region> r, bool from_capture);
628 };
629 
630 
632  public:
633  MIDITrigger (uint32_t index, TriggerBox&);
635 
636  bool playable() const { return rt_midibuffer.load() || _region; }
637 
639  void disarm ();
640 
641  template<bool actually_run> pframes_t midi_run (BufferSet&, samplepos_t start_sample, samplepos_t end_sample,
642  Temporal::Beats const & start_beats, Temporal::Beats const & end_beats, pframes_t nframes, pframes_t offset, double bpm, pframes_t& quantize_offset);
643 
644  pframes_t run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, Temporal::Beats const & start, Temporal::Beats const & end, pframes_t nframes, pframes_t dest_offset, double bpm, pframes_t& quantize_offset) {
645  return midi_run<true> (bufs, start_sample, end_sample, start, end, nframes, dest_offset, bpm, quantize_offset);
646  }
647 
648  void set_start (timepos_t const &);
649  void set_end (timepos_t const &);
650  void set_legato_offset (timepos_t const &);
651  void set_length (timecnt_t const &);
653  timepos_t end() const; /* offset from start of data */
654  bool probably_oneshot () const;
655 
658 
659  int set_region_in_worker_thread (std::shared_ptr<Region>);
660  int set_region_in_worker_thread_from_capture (std::shared_ptr<Region>);
661  void jump_start ();
662  void shutdown (BufferSet& bufs, pframes_t dest_offset);
663  void jump_stop (BufferSet& bufs, pframes_t dest_offset);
664 
665  XMLNode& get_state () const;
666  int set_state (const XMLNode&, int version);
667 
671 
674  void unset_patch_change (uint8_t channel);
676  bool patch_change_set (uint8_t channel) const;
677 
678  /* It's possible that a portion of a midi file would use a subset of the total channels used, so store that info in the segment descriptor */
679  Evoral::SMF::UsedChannels used_channels() const { return ui_state.used_channels; }
681 
682  /* theoretically, MIDI files can have a dedicated tempo outside the session tempo map (*un-stretched*) but this is currently unimplemented */
683  /* boilerplate tempo functions are provided here so we don't have to do constant dynamic_cast checks to use the tempo+stretch APIs */
684  virtual double segment_tempo() const {return 120.0;}
685  virtual void set_segment_tempo (double t) {}
686  virtual void setup_stretcher () {}
687 
688  void set_channel_map (int channel, int target);
689  void unset_channel_map (int channel);
690  int channel_map (int channel);
691  std::vector<int> const & channel_map() const { return _channel_map; }
692 
693  void check_edit_swap (timepos_t const &, bool playing, BufferSet&);
695 
696  RTMidiBufferBeats const & rt_midi_buffer() const { return *rt_midibuffer.load(); }
697 
698  Temporal::Beats play_start() const { return _play_start; }
699  Temporal::Beats play_end() const { return _play_end; }
700  Temporal::Beats loop_start() const { return _loop_start; }
701  Temporal::Beats loop_end() const { return _loop_end; }
702 
703  protected:
704  void retrigger ();
705  void _arm (Temporal::BBT_Offset const &);
706  void adjust_bounds (Temporal::timepos_t const & start, Temporal::timepos_t const & end, Temporal::timecnt_t const & length, bool from_region);
708 
709  private:
711 
713 
714  Temporal::DoubleableBeats data_length; /* using timestamps from data */
717 
720 
721  std::shared_ptr<MidiModel> _model;
724 
731 
732  std::atomic<RTMidiBufferBeats*> rt_midibuffer;
733  uint32_t iter; /* index into the above RTMidiBufferBeats for current playback */
734 
735  struct MIDIPendingSwap : public PendingSwap {
737 
739  ~MIDIPendingSwap() { delete rt_midibuffer; }
740  };
741 
743 
744  int load_data (std::shared_ptr<MidiRegion>);
746  void _startup (BufferSet&, pframes_t dest_offset, Temporal::BBT_Offset const &);
748 };
749 
751 {
752  public:
755 
756  static void init_request_pool() { Request::init_pool(); }
757 
758  void set_region (TriggerBox&, uint32_t slot, std::shared_ptr<Region>);
761 
762  void summon();
763  void stop();
765 
766  private:
767  static void* _thread_work(void *arg);
768  void* thread_work();
769 
770  enum RequestType {
774  BuildSourceAndRegion
775  };
776 
777  struct Request {
778 
779  Request (RequestType t) : type (t) {}
780 
782  /* for set region */
784  uint32_t slot;
785  std::shared_ptr<Region> region;
786  /* for DeleteTrigger and BuildSourceAndRegion */
790 
791  void* operator new (size_t);
792  void operator delete (void* ptr, size_t);
793 
795  static void init_pool ();
796  };
797 
798  pthread_t thread;
800 
804  void build_source (Trigger*, Temporal::timecnt_t const & duration, Temporal::timepos_t const &);
807 };
808 
809 struct CueRecord {
810  int32_t cue_number;
812 
813  CueRecord (int32_t cn, samplepos_t t): cue_number (cn), when (t) {}
814  CueRecord () : cue_number (0), when (0) {}
815 
816  static const int32_t stop_all = INT32_MAX;
817 };
818 
820 
821 struct SlotArmInfo {
824 
825  void reset (Trigger&);
826 
836  RubberBand::RubberBandStretcher* stretcher;
837 };
838 
839 class LIBARDOUR_API TriggerBox : public Processor, public std::enable_shared_from_this<TriggerBox>
840 {
841  public:
842 
843 #ifdef MIXBUS
844  static const int32_t default_triggers_per_box = 8;
845 #else
846  static const int32_t default_triggers_per_box = 16;
847 #endif
848 
851 
853  static bool cue_recording () { return _cue_recording; }
854  static void set_cue_recording (bool yn);
856 
857  void set_record_enabled (bool yn);
858  bool rec_enabled() const;
859  RecordState record_enabled() const { return _record_state; }
861  PBD::Signal<void(Trigger const *)> ReCountIn;
863  static PBD::Signal<void(Trigger const *)> RegionCaptured;
864 
865  void arm_from_another_thread (Trigger& slot, samplepos_t, uint32_t chans, Temporal::BBT_Offset const &);
867  void disarm();
868  void disarm_all();
869  bool armed() const { return (bool) _arm_info.load(); }
871 
872  void run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool result_required);
873  void run_cycle (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes);
876 
877  bool empty() const { return _active_slots == 0; }
879 
880  int32_t order() const { return _order; }
881  void set_order(int32_t n);
882 
883  typedef std::vector<TriggerPtr> Triggers;
884 
885  TriggerPtr trigger (Triggers::size_type);
886 
887  void bang_trigger_at (Triggers::size_type row, float velocity = 1.0f);
888  void unbang_trigger_at (Triggers::size_type row);
889 
891 
892  void fast_forward (CueEvents const &, samplepos_t transport_position);
893  bool fast_forwarding() const { return _fast_forwarding; }
894 
895  void set_pending (uint32_t slot, Trigger*);
896 
897  XMLNode& get_state () const;
898  int set_state (const XMLNode&, int version);
899 
900  void deep_sources (std::set<std::shared_ptr<Source>>&);
901  void used_regions (std::set<std::shared_ptr<Region>>&);
902 
903  void set_from_path (uint32_t slot, std::string const & path);
904  void set_from_selection (uint32_t slot, std::shared_ptr<Region>);
905 
906  DataType data_type() const { return _data_type; }
907 
910 
911  TriggerPtr currently_playing() const { return _currently_playing; }
912 
914 
916  void clear_cue (int cue);
917  void set_all_follow_action (ARDOUR::FollowAction const &, uint32_t n=0);
920  void set_all_probability (int zero_to_a_hundred);
921 
922  /* Returns a negative value is there is no active Trigger, or a value between 0
923  * and 1.0 if there is, corresponding to the value of position_as_fraction() for
924  * the active Trigger.
925  */
926  double position_as_fraction() const;
927 
928  void queue_explict (uint32_t);
931 
932  void set_region (uint32_t slot, std::shared_ptr<Region> region);
933 
937 
938  void enqueue_trigger_state_for_region (std::shared_ptr<Region>, std::shared_ptr<Trigger::UIState>);
939 
941 
942  /* valid only within the ::run() call tree */
943  int32_t active_scene() const { return _active_scene; }
944 
945  PBD::Signal<void(uint32_t)> TriggerSwapped;
946 
952  };
953 
954  /* This is null for TriggerBoxen constructed with DataType::AUDIO */
956 
957  static bool lookup_custom_midi_binding (std::vector<uint8_t> const &, int& x, int& y);
958  static void add_custom_midi_binding (std::vector<uint8_t> const &, int x, int y);
959  static void remove_custom_midi_binding (int x, int y);
961  static int save_custom_midi_bindings (std::string const & path);
962  static int load_custom_midi_bindings (XMLNode const &);
964 
965  void begin_midi_learn (int index);
966  void midi_unlearn (int index);
968  bool learning () const { return _learning; }
970 
971  static Temporal::BBT_Offset assumed_trigger_duration () { return _assumed_trigger_duration; }
973 
974  static TriggerMidiMapMode midi_map_mode () { return _midi_map_mode; }
976 
977  static int first_midi_note() { return _first_midi_note; }
978  static void set_first_midi_note (int n);
979 
980  static void init ();
981  static void static_init (Session&);
982  static void begin_process_cycle ();
983 
985 
987 
989 
992 
993  std::shared_ptr<MidiBuffer> get_gui_feed_buffer () const;
994 
995  void dump (std::ostream &) const;
996 
998 
999  /* return start time for capture; only valid if is_set is true upon return */
1000  Temporal::Beats start_time (bool& is_set) const;
1001 
1003 
1004  private:
1005  struct Requests {
1006  std::atomic<bool> stop_all;
1007 
1008  Requests () : stop_all (false) {}
1009  };
1010 
1012 
1014  int32_t _order;
1015  mutable PBD::RWLock trigger_lock; /* protects all_triggers */
1017 
1018  typedef std::vector<Trigger*> PendingTriggers;
1020 
1021  PBD::RingBuffer<uint32_t> explicit_queue; /* user queued triggers */
1025  int32_t _active_scene;
1026  int32_t _active_slots;
1031 
1033 
1034  void maybe_capture (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes);
1036 
1037  /* These four are accessed (read/write) only from process() context */
1038 
1039  void drop_triggers ();
1042  int determine_next_trigger (uint32_t n);
1043  void stop_all ();
1044 
1045  void maybe_swap_pending (uint32_t);
1046 
1047  void parameter_changed (std::string const &);
1048  static void static_parameter_changed (std::string const &);
1049 
1050  static int _first_midi_note;
1052 
1053  struct Request {
1054  enum Type {
1056  };
1057 
1059 
1060  /* cannot use a union here because we need Request to have a
1061  * "trivial" constructor.
1062  */
1063 
1065  void* ptr;
1066  int32_t slot;
1067 
1068  Request (Type t) : type (t) {}
1069 
1071  static void init_pool();
1072 
1073  void* operator new (size_t);
1074  void operator delete (void* ptr, size_t);
1075  };
1076 
1079 
1082 
1085  int handle_stopped_trigger (BufferSet& bufs, pframes_t dest_offset);
1086 
1088  std::atomic<SlotArmInfo*> _arm_info;
1090 
1096 
1097  typedef std::map<std::vector<uint8_t>,std::pair<int,int> > CustomMidiMap;
1100 
1102  static std::shared_ptr<MIDI::Parser> input_parser;
1104  static void input_port_check ();
1106  static std::shared_ptr<MidiPort> current_input;
1107 
1108  static bool _learning;
1109  static std::pair<int,int> learning_for;
1110 
1111  static void init_pool();
1112 
1113  static std::atomic<int> active_trigger_boxes;
1114  static std::atomic<bool> _cue_recording;
1115  static bool roll_requested;
1116  static void maybe_request_roll (Session&);
1117 };
1118 
1120 {
1121  public:
1123  TriggerReference (std::shared_ptr<ARDOUR::TriggerBox> b, uint32_t s) : weak_box (b), _slot (s) {}
1124 
1125  std::shared_ptr<ARDOUR::Trigger> trigger() const { std::shared_ptr<ARDOUR::TriggerBox> box (weak_box.lock()); return box ? box->trigger (_slot) : std::shared_ptr<ARDOUR::Trigger>(); }
1126  void set (std::shared_ptr<ARDOUR::TriggerBox> b, uint32_t s) { weak_box = b; _slot = s; }
1127  uint32_t slot() const { return _slot; }
1128  std::shared_ptr<ARDOUR::TriggerBox> box() const { return weak_box.lock(); }
1129 
1130  bool operator== (TriggerReference const & other) {
1131  return _slot == other._slot && box() == other.box();
1132  }
1133 
1134  private:
1135  std::weak_ptr<ARDOUR::TriggerBox> weak_box;
1136  uint32_t _slot;
1137 };
1138 
1139 namespace Properties {
1159  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> patch_change; /* type not important */
1160  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> channel_map; /* type not important */
1161  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> used_channels; /* type not important */
1162  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> region; /* type not important */
1163 
1164  LIBARDOUR_API extern PBD::PropertyDescriptor<bool> tempo_meter; /* only used to transmit changes, not storage */
1165 }
1166 
1167 
1168 } // namespace ARDOUR
1169 
1170 namespace PBD {
1174 } /* namespace PBD */
samplecnt_t to_pad
Definition: triggerbox.h:617
RubberBand::RubberBandStretcher * _stretcher
Definition: triggerbox.h:608
samplepos_t _legato_offset
Definition: triggerbox.h:614
bool stretching() const
int set_region_in_worker_thread_from_capture(std::shared_ptr< Region >)
SegmentDescriptor get_segment_descriptor() const
RubberBand::RubberBandStretcher * alloc_stretcher() const
samplepos_t last_readable_sample
Definition: triggerbox.h:613
void set_segment_tempo(double t)
timepos_t compute_end(Temporal::TempoMap::SharedPtr const &, Temporal::BBT_Time const &, samplepos_t, Temporal::Beats &)
void captured(SlotArmInfo &)
void drop_data(AudioData &)
samplecnt_t read_index
Definition: triggerbox.h:612
samplecnt_t to_drop
Definition: triggerbox.h:618
XMLNode & get_state() const
uint32_t channels() const
Definition: triggerbox.h:570
AudioTrigger(uint32_t index, TriggerBox &)
int load_pending_data(PendingSwap &)
double segment_tempo() const
Definition: triggerbox.h:542
RubberBand::RubberBandStretcher * stretcher()
Definition: triggerbox.h:563
void set_length(timecnt_t const &)
PendingSwap * pending_factory() const
size_t data_length() const
Definition: triggerbox.h:590
int set_state(const XMLNode &, int version)
int set_region_in_worker_thread(std::shared_ptr< Region >)
double segment_beatcnt()
Definition: triggerbox.h:545
virtual void setup_stretcher()
void _startup(BufferSet &, pframes_t dest_offset, Temporal::BBT_Offset const &)
int set_region_in_worker_thread_internal(std::shared_ptr< Region > r, bool from_capture)
void set_legato_offset(timepos_t const &)
void set_segment_beatcnt(double count)
StretchMode stretch_mode() const
Definition: triggerbox.h:539
void set_stretch_mode(StretchMode)
samplecnt_t retrieved
Definition: triggerbox.h:615
samplecnt_t got_stretcher_padding
Definition: triggerbox.h:616
bool probably_oneshot() const
int load_data(std::shared_ptr< AudioRegion >, AudioData &)
bool playable() const
Definition: triggerbox.h:537
void check_edit_swap(timepos_t const &, bool playing, BufferSet &)
pframes_t audio_run(BufferSet &bufs, samplepos_t start_sample, samplepos_t end_sample, Temporal::Beats const &start, Temporal::Beats const &end, pframes_t nframes, pframes_t dest_offset, double bpm, pframes_t &quantize_offset)
Sample const * audio_data(size_t n) const
pframes_t run(BufferSet &bufs, samplepos_t start_sample, samplepos_t end_sample, Temporal::Beats const &start, Temporal::Beats const &end, pframes_t nframes, pframes_t dest_offset, double bpm, pframes_t &quantize_offset)
Definition: triggerbox.h:533
void start_and_roll_to(samplepos_t start, samplepos_t position, uint32_t cnt)
void jump_stop(BufferSet &bufs, pframes_t dest_offset)
RTMidiBufferBeats const & rt_midi_buffer() const
Definition: triggerbox.h:696
void captured(SlotArmInfo &)
void set_legato_offset(timepos_t const &)
samplepos_t last_event_samples
Definition: triggerbox.h:716
void check_edit_swap(timepos_t const &, bool playing, BufferSet &)
void shutdown(BufferSet &bufs, pframes_t dest_offset)
PendingSwap * pending_factory() const
Temporal::Beats play_start() const
Definition: triggerbox.h:698
Temporal::Beats loop_start() const
Definition: triggerbox.h:700
uint32_t last_event_index
Definition: triggerbox.h:730
void _startup(BufferSet &, pframes_t dest_offset, Temporal::BBT_Offset const &)
XMLNode & get_state() const
Temporal::Beats _play_start
Definition: triggerbox.h:725
void set_used_channels(Evoral::SMF::UsedChannels)
void compute_and_set_length()
void estimate_midi_patches()
Temporal::Beats _loop_end
Definition: triggerbox.h:728
void _arm(Temporal::BBT_Offset const &)
virtual double segment_tempo() const
Definition: triggerbox.h:684
Temporal::DoubleableBeats last_event_beats
Definition: triggerbox.h:715
Temporal::Beats _loop_start
Definition: triggerbox.h:727
void unset_all_patch_changes()
timepos_t compute_end(Temporal::TempoMap::SharedPtr const &, Temporal::BBT_Time const &, samplepos_t, Temporal::Beats &)
bool patch_change_set(uint8_t channel) const
void unset_channel_map(int channel)
Temporal::Beats final_beat
Definition: triggerbox.h:712
Temporal::Beats _play_end
Definition: triggerbox.h:726
pframes_t midi_run(BufferSet &, samplepos_t start_sample, samplepos_t end_sample, Temporal::Beats const &start_beats, Temporal::Beats const &end_beats, pframes_t nframes, pframes_t offset, double bpm, pframes_t &quantize_offset)
void unset_patch_change(uint8_t channel)
void set_patch_change(Evoral::PatchChange< MidiBuffer::TimeType > const &)
int set_state(const XMLNode &, int version)
MIDITrigger(uint32_t index, TriggerBox &)
pframes_t run(BufferSet &bufs, samplepos_t start_sample, samplepos_t end_sample, Temporal::Beats const &start, Temporal::Beats const &end, pframes_t nframes, pframes_t dest_offset, double bpm, pframes_t &quantize_offset)
Definition: triggerbox.h:644
bool playable() const
Definition: triggerbox.h:636
timepos_t end() const
std::vector< int > const & channel_map() const
Definition: triggerbox.h:691
std::shared_ptr< MidiModel > _model
Definition: triggerbox.h:721
Evoral::SMF::UsedChannels used_channels() const
Definition: triggerbox.h:679
bool probably_oneshot() const
uint32_t first_event_index
Definition: triggerbox.h:729
Temporal::Beats play_end() const
Definition: triggerbox.h:699
Temporal::Beats loop_end() const
Definition: triggerbox.h:701
virtual void setup_stretcher()
Definition: triggerbox.h:686
Temporal::BBT_Offset _legato_offset
Definition: triggerbox.h:719
void set_length(timecnt_t const &)
void jump_stop(BufferSet &bufs, pframes_t dest_offset)
void model_contents_changed()
int load_pending_data(PendingSwap &)
virtual void set_segment_tempo(double t)
Definition: triggerbox.h:685
int channel_map(int channel)
SegmentDescriptor get_segment_descriptor() const
void set_channel_map(int channel, int target)
std::atomic< RTMidiBufferBeats * > rt_midibuffer
Definition: triggerbox.h:732
void adjust_bounds(Temporal::timepos_t const &start, Temporal::timepos_t const &end, Temporal::timecnt_t const &length, bool from_region)
Evoral::PatchChange< MidiBuffer::TimeType > const patch_change(uint8_t) const
void set_start(timepos_t const &)
int set_region_in_worker_thread(std::shared_ptr< Region >)
timepos_t start_offset() const
PBD::ScopedConnection content_connection
Definition: triggerbox.h:722
int load_data(std::shared_ptr< MidiRegion >)
Temporal::DoubleableBeats data_length
Definition: triggerbox.h:714
void start_and_roll_to(samplepos_t start, samplepos_t position, uint32_t cnt)
void set_end(timepos_t const &)
Temporal::BBT_Offset _start_offset
Definition: triggerbox.h:718
int set_region_in_worker_thread_from_capture(std::shared_ptr< Region >)
CrossThreadChannel _xthread
Definition: triggerbox.h:801
void build_audio_source(AudioTrigger *, Temporal::timecnt_t const &, Temporal::timepos_t const &)
void build_midi_source(MIDITrigger *, Temporal::timecnt_t const &, Temporal::timepos_t const &)
void set_region(TriggerBox &, uint32_t slot, std::shared_ptr< Region >)
void build_source(Trigger *, Temporal::timecnt_t const &duration, Temporal::timepos_t const &)
void request_build_source(Trigger *t, Temporal::timecnt_t const &duration, Temporal::timepos_t const &)
void queue_request(Request *)
static void init_request_pool()
Definition: triggerbox.h:756
void delete_trigger(Trigger *)
void request_delete_trigger(Trigger *t)
PBD::RingBuffer< Request * > requests
Definition: triggerbox.h:799
static void * _thread_work(void *arg)
static TriggerBoxThread * worker
Definition: triggerbox.h:984
static void static_parameter_changed(std::string const &)
void used_regions(std::set< std::shared_ptr< Region >> &)
int32_t active_scene() const
Definition: triggerbox.h:943
static TriggerMidiMapMode _midi_map_mode
Definition: triggerbox.h:1051
static void init()
static PBD::Signal< void()> TriggerRecEnableChanged
Definition: triggerbox.h:862
static PBD::ScopedConnectionList static_connections
Definition: triggerbox.h:1105
void process_ui_trigger_requests()
TriggerBox(Session &, DataType dt)
double position_as_fraction() const
void set_record_enabled(bool yn)
void process_request(BufferSet &, Request *)
bool configure_io(ChanCount in, ChanCount out)
PendingTriggers pending
Definition: triggerbox.h:1019
EventRingBuffer< samplepos_t > _gui_feed_fifo
Definition: triggerbox.h:1094
RequestBuffer requests
Definition: triggerbox.h:1078
PBD::ScopedConnection stop_all_connection
Definition: triggerbox.h:1087
void fast_forward_nothing_to_do()
void process_requests(BufferSet &)
Temporal::Beats start_time(bool &is_set) const
TriggerPtr get_next_trigger()
static PBD::Signal< void(PBD::PropertyChange, int)> TriggerBoxPropertyChange
Definition: triggerbox.h:991
static void static_init(Session &)
void maybe_swap_pending(uint32_t)
Triggers all_triggers
Definition: triggerbox.h:1016
void set_all_quantization(Temporal::BBT_Offset const &)
void set_armed(SlotArmInfo *)
static TriggerMidiMapMode midi_map_mode()
Definition: triggerbox.h:974
void deep_sources(std::set< std::shared_ptr< Source >> &)
void cancel_locate_armed()
int set_state(const XMLNode &, int version)
static void maybe_request_roll(Session &)
void set_from_selection(uint32_t slot, std::shared_ptr< Region >)
XMLNode & get_state() const
PBD::Signal< void(uint32_t)> TriggerSwapped
Definition: triggerbox.h:945
int handle_stopped_trigger(BufferSet &bufs, pframes_t dest_offset)
static void set_first_midi_note(int n)
static void add_custom_midi_binding(std::vector< uint8_t > const &, int x, int y)
void dump(std::ostream &) const
static bool _learning
Definition: triggerbox.h:1108
TriggerPtr trigger(Triggers::size_type)
int32_t order() const
Definition: triggerbox.h:880
static void init_pool()
SlotArmInfo _the_arm_info
Definition: triggerbox.h:1089
static CueRecords cue_records
Definition: triggerbox.h:852
int determine_next_trigger(uint32_t n)
void non_realtime_transport_stop(samplepos_t now, bool flush)
TriggerPtr peek_next_trigger()
static void midi_input_handler(MIDI::Parser &, MIDI::byte *, size_t, samplecnt_t)
static void set_midi_map_mode(TriggerMidiMapMode m)
static PBD::ScopedConnection midi_input_connection
Definition: triggerbox.h:1103
DataType data_type() const
Definition: triggerbox.h:906
void begin_midi_learn(int index)
static void clear_custom_midi_bindings()
PBD::Signal< void(samplecnt_t)> Captured
Definition: triggerbox.h:997
static std::pair< int, int > learning_for
Definition: triggerbox.h:1109
PBD::RingBuffer< Request * > RequestBuffer
Definition: triggerbox.h:1077
bool armed() const
Definition: triggerbox.h:869
static Temporal::BBT_Offset assumed_trigger_duration()
Definition: triggerbox.h:971
bool rec_enabled() const
void midi_unlearn(int index)
static void begin_process_cycle()
bool can_support_io_configuration(const ChanCount &in, ChanCount &out)
PBD::Signal< void(Trigger const *)> ReCountIn
Definition: triggerbox.h:861
void non_realtime_locate(samplepos_t now)
void set_all_launch_style(ARDOUR::Trigger::LaunchStyle)
static bool lookup_custom_midi_binding(std::vector< uint8_t > const &, int &x, int &y)
static std::atomic< int > active_trigger_boxes
Definition: triggerbox.h:1113
static void set_cue_recording(bool yn)
void fast_forward(CueEvents const &, samplepos_t transport_position)
void set_all_follow_action(ARDOUR::FollowAction const &, uint32_t n=0)
std::map< std::vector< uint8_t >, std::pair< int, int > > CustomMidiMap
Definition: triggerbox.h:1097
static std::shared_ptr< MidiPort > current_input
Definition: triggerbox.h:1106
void set_pending(uint32_t slot, Trigger *)
static int first_midi_note()
Definition: triggerbox.h:977
static CustomMidiMap _custom_midi_map
Definition: triggerbox.h:1098
void set_order(int32_t n)
PBD::Signal< void()> ArmedChanged
Definition: triggerbox.h:870
void clear_cue(int cue)
static PBD::Mutex _bindings_mutex
Definition: triggerbox.h:1099
static PBD::Signal< void(Trigger const *)> RegionCaptured
Definition: triggerbox.h:863
void maybe_capture(BufferSet &bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes)
PBD::Signal< void()> EmptyStatusChanged
Definition: triggerbox.h:878
void parameter_changed(std::string const &)
PBD::RWLock trigger_lock
Definition: triggerbox.h:1015
static Temporal::BBT_Offset _assumed_trigger_duration
Definition: triggerbox.h:1011
void bang_trigger_at(Triggers::size_type row, float velocity=1.0f)
PBD::Mutex _gui_feed_reset_mutex
Definition: triggerbox.h:1095
PBD::Signal< void()> RecEnableChanged
Definition: triggerbox.h:860
static void remove_custom_midi_binding(int x, int y)
static bool roll_requested
Definition: triggerbox.h:1115
void setup_arm_info_bounds(SlotArmInfo &ai, samplepos_t, Trigger &slot, Temporal::BBT_Offset const &duration)
std::vector< Trigger * > PendingTriggers
Definition: triggerbox.h:1018
RecordState _record_state
Definition: triggerbox.h:1030
std::shared_ptr< MidiBuffer > get_gui_feed_buffer() const
static int save_custom_midi_bindings(std::string const &path)
PBD::PCGRand _pcg
Definition: triggerbox.h:1032
std::vector< TriggerPtr > Triggers
Definition: triggerbox.h:883
PBD::RingBuffer< uint32_t > explicit_queue
Definition: triggerbox.h:1021
void arm_from_another_thread(Trigger &slot, samplepos_t, uint32_t chans, Temporal::BBT_Offset const &)
static PBD::Signal< void()> TriggerMIDILearned
Definition: triggerbox.h:969
void queue_explict(uint32_t)
static std::atomic< bool > _cue_recording
Definition: triggerbox.h:1114
static void set_assumed_trigger_duration(Temporal::BBT_Offset const &)
bool learning() const
Definition: triggerbox.h:968
void realtime_handle_transport_stopped()
void unbang_trigger_at(Triggers::size_type row)
static PBD::PropertyChange all_trigger_props()
void process_midi_trigger_requests(BufferSet &)
static void start_transport_stop(Session &)
bool fast_forwarding() const
Definition: triggerbox.h:893
static XMLNode * get_custom_midi_binding_state()
bool empty() const
Definition: triggerbox.h:877
TriggerPtr currently_playing() const
Definition: triggerbox.h:911
static int load_custom_midi_bindings(XMLNode const &)
void add_trigger(TriggerPtr)
void run(BufferSet &bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool result_required)
static bool cue_recording()
Definition: triggerbox.h:853
void send_property_change(PBD::PropertyChange pc)
void enqueue_trigger_state_for_region(std::shared_ptr< Region >, std::shared_ptr< Trigger::UIState >)
static PBD::Signal< void()> CueRecordingChanged
Definition: triggerbox.h:855
static int _first_midi_note
Definition: triggerbox.h:1050
void run_cycle(BufferSet &bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes)
static void input_port_check()
void set_region(uint32_t slot, std::shared_ptr< Region > region)
void set_from_path(uint32_t slot, std::string const &path)
std::atomic< SlotArmInfo * > _arm_info
Definition: triggerbox.h:1088
void set_all_probability(int zero_to_a_hundred)
void stop_all_immediately()
MidiStateTracker * tracker
Definition: triggerbox.h:955
TriggerPtr trigger_by_id(PBD::ID)
static std::shared_ptr< MIDI::Parser > input_parser
Definition: triggerbox.h:1102
TriggerPtr _currently_playing
Definition: triggerbox.h:1022
RecordState record_enabled() const
Definition: triggerbox.h:859
TriggerReference(std::shared_ptr< ARDOUR::TriggerBox > b, uint32_t s)
Definition: triggerbox.h:1123
std::shared_ptr< ARDOUR::Trigger > trigger() const
Definition: triggerbox.h:1125
void set(std::shared_ptr< ARDOUR::TriggerBox > b, uint32_t s)
Definition: triggerbox.h:1126
std::shared_ptr< ARDOUR::TriggerBox > box() const
Definition: triggerbox.h:1128
std::weak_ptr< ARDOUR::TriggerBox > weak_box
Definition: triggerbox.h:1135
uint32_t slot() const
Definition: triggerbox.h:1127
bool operator==(TriggerReference const &other)
Definition: triggerbox.h:1130
std::atomic< PendingSwap * > old_pending_swap
Definition: triggerbox.h:518
uint32_t loop_count() const
Definition: triggerbox.h:383
void process_state_requests(BufferSet &bufs, pframes_t dest_offset)
samplepos_t final_process_index
Definition: triggerbox.h:446
double _estimated_tempo
Definition: triggerbox.h:475
Temporal::Meter meter() const
Definition: triggerbox.h:411
virtual void shutdown(BufferSet &bufs, pframes_t dest_offset)
bool will_not_follow() const
samplecnt_t process_index
Definition: triggerbox.h:445
PBD::Property< bool > _cue_isolated
Definition: triggerbox.h:163
virtual void set_patch_change(Evoral::PatchChange< MidiBuffer::TimeType > const &)
Definition: triggerbox.h:403
uint32_t _loop_cnt
Definition: triggerbox.h:456
std::vector< int > _channel_map
Definition: triggerbox.h:468
PBD::Property< LaunchStyle > _launch_style
Definition: triggerbox.h:150
virtual Evoral::SMF::UsedChannels used_channels() const
Definition: triggerbox.h:399
virtual Evoral::PatchChange< MidiBuffer::TimeType > const patch_change(uint8_t) const
Definition: triggerbox.h:404
PBD::Property< Temporal::BBT_Offset > _quantization
Definition: triggerbox.h:155
Temporal::BBT_Offset _start_quantization
Definition: triggerbox.h:491
PBD::Property< FollowAction > _follow_action0
Definition: triggerbox.h:151
bool armed() const
Definition: triggerbox.h:303
void set_ui(void *)
TriggerBox & box() const
Definition: triggerbox.h:388
pframes_t compute_next_transition(samplepos_t start_sample, Temporal::Beats const &start, Temporal::Beats const &end, pframes_t nframes, Temporal::BBT_Argument &t_bbt, Temporal::Beats &t_beats, samplepos_t &t_samples, Temporal::TempoMap::SharedPtr const &tmap)
PBD::Property< FollowAction > _follow_action1
Definition: triggerbox.h:152
std::atomic< int > _bang
Definition: triggerbox.h:452
virtual bool patch_change_set(uint8_t channel) const
Definition: triggerbox.h:407
void begin_stop(bool explicit_stop=false)
PBD::Property< float > _velocity_effect
Definition: triggerbox.h:161
Temporal::Meter _meter
Definition: triggerbox.h:488
virtual PendingSwap * pending_factory() const =0
PBD::Property< bool > _stretchable
Definition: triggerbox.h:162
samplepos_t transition_samples
Definition: triggerbox.h:340
static PBD::Signal< void(Trigger const *)> TriggerArmChanged
Definition: triggerbox.h:305
void region_property_change(PBD::PropertyChange const &)
virtual int load_pending_data(PendingSwap &)=0
void set_region_internal(std::shared_ptr< Region >)
double position_as_fraction() const
int next_trigger() const
Definition: triggerbox.h:365
virtual void io_change()
Definition: triggerbox.h:292
static void request_trigger_delete(Trigger *t)
static Trigger *const MagicClearPointerValue
Definition: triggerbox.h:420
PBD::ScopedConnection region_connection
Definition: triggerbox.h:495
PBD::Property< int > _follow_action_probability
Definition: triggerbox.h:153
virtual void jump_stop(BufferSet &bufs, pframes_t dest_offset)
virtual int set_region_in_worker_thread(std::shared_ptr< Region >)=0
virtual void check_edit_swap(timepos_t const &time, bool playing, BufferSet &bufs)=0
virtual void unset_patch_change(uint8_t channel)
Definition: triggerbox.h:405
virtual timepos_t compute_end(Temporal::TempoMap::SharedPtr const &, Temporal::BBT_Time const &, samplepos_t, Temporal::Beats &)=0
virtual void jump_start()
virtual void start_and_roll_to(samplepos_t start, samplepos_t position, uint32_t cnt)=0
void when_stopped_during_run(BufferSet &bufs, pframes_t dest_offset)
std::atomic< int > _unbang
Definition: triggerbox.h:453
bool will_follow() const
Definition: triggerbox.h:315
PBD::Property< Temporal::BBT_Offset > _capture_duration
Definition: triggerbox.h:157
int set_state(const XMLNode &, int version)
State state() const
Definition: triggerbox.h:325
PBD::Signal< void()> ArmChanged
Definition: triggerbox.h:304
PBD::Property< std::string > _name
Definition: triggerbox.h:169
virtual ~Trigger()
Definition: triggerbox.h:143
PBD::Property< gain_t > _gain
Definition: triggerbox.h:160
std::shared_ptr< TriggerBox > boxptr() const
bool active() const
Definition: triggerbox.h:324
static void make_property_quarks()
void copy_to_ui_state()
uint32_t index() const
Definition: triggerbox.h:334
virtual SegmentDescriptor get_segment_descriptor() const =0
Temporal::BBT_Argument 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 void disarm()
samplepos_t expected_end_sample
Definition: triggerbox.h:490
std::shared_ptr< Region > the_region() const
Definition: triggerbox.h:331
PBD::Property< uint32_t > _follow_count
Definition: triggerbox.h:154
virtual void set_used_channels(Evoral::SMF::UsedChannels)
Definition: triggerbox.h:400
virtual int set_region_in_worker_thread_from_capture(std::shared_ptr< Region >)=0
PBD::Property< StretchMode > _stretch_mode
Definition: triggerbox.h:165
void set_ui_state(UIState &state)
virtual void _arm(Temporal::BBT_Offset const &)
Trigger(uint32_t index, TriggerBox &)
virtual void set_legato_offset(timepos_t const &offset)=0
void shutdown_from_fwd()
timepos_t current_pos() const
gain_t _pending_velocity_gain
Definition: triggerbox.h:460
virtual void captured(SlotArmInfo &)
Definition: triggerbox.h:298
uint32_t _index
Definition: triggerbox.h:454
virtual void retrigger()
bool cue_launched() const
Definition: triggerbox.h:318
void set_pending(Trigger *)
void arm(Temporal::BBT_Offset duration=Temporal::BBT_Offset())
Definition: triggerbox.h:299
virtual void bounds_changed(Temporal::timepos_t const &start, Temporal::timepos_t const &end, Temporal::timecnt_t const &len)
virtual void setup_stretcher()=0
virtual bool probably_oneshot() const =0
void set_velocity_gain(gain_t g)
Definition: triggerbox.h:413
gain_t _velocity_gain
Definition: triggerbox.h:461
void stop_quantized()
virtual void _startup(BufferSet &, pframes_t dest_offset, Temporal::BBT_Offset const &)
UIState ui_state
Definition: triggerbox.h:447
std::shared_ptr< Region > _region
Definition: triggerbox.h:444
void startup_from_ffwd(BufferSet &, uint32_t loop_cnt)
std::atomic< PendingSwap * > pending_swap
Definition: triggerbox.h:517
virtual double segment_tempo() const =0
PBD::Property< bool > _legato
Definition: triggerbox.h:159
virtual void unset_all_patch_changes()
Definition: triggerbox.h:406
Trigger * swap_pending(Trigger *)
PBD::Property< color_t > _color
Definition: triggerbox.h:170
void begin_switch(TriggerPtr)
Evoral::SMF::UsedChannels _used_channels
Definition: triggerbox.h:466
bool compute_quantized_transition(samplepos_t start_sample, Temporal::Beats const &start, Temporal::Beats const &end, Temporal::BBT_Argument &t_bbt, Temporal::Beats &t_beats, samplepos_t &t_samples, Temporal::TempoMap::SharedPtr const &tmap, Temporal::BBT_Offset const &q)
XMLNode & get_state() const
PBD::Property< Temporal::BBT_Offset > _follow_length
Definition: triggerbox.h:156
static PBD::Signal< void(PBD::PropertyChange, Trigger *)> TriggerPropertyChange
Definition: triggerbox.h:433
void set_region(std::shared_ptr< Region >, bool use_thread=true)
double estimated_tempo() const
Definition: triggerbox.h:391
void get_ui_state(UIState &state) const
void * ui() const
Definition: triggerbox.h:386
UIRequests _requests
Definition: triggerbox.h:449
std::atomic< Trigger * > _pending
Definition: triggerbox.h:493
void set_scene_switch(bool yn)
Temporal::BBT_Time _transition_bbt
Definition: triggerbox.h:342
void bang(float velocity=1.0f)
Temporal::Beats transition_beats
Definition: triggerbox.h:341
void maybe_compute_next_transition(samplepos_t start_sample, Temporal::Beats const &start, Temporal::Beats const &end, pframes_t &nframes, pframes_t &dest_offset)
void update_properties()
PBD::Property< bool > _use_follow_length
Definition: triggerbox.h:158
Temporal::BBT_Offset _nxt_quantization
Definition: triggerbox.h:492
virtual void set_segment_tempo(double t)=0
virtual bool playable() const =0
void send_property_change(PBD::PropertyChange pc)
virtual pframes_t run(BufferSet &, samplepos_t start_sample, samplepos_t end_sample, Temporal::Beats const &start, Temporal::Beats const &end, pframes_t nframes, pframes_t offset, double bpm, pframes_t &quantize_offset)=0
void set_next_trigger(int n)
void start_and_roll_to(samplepos_t start_pos, samplepos_t end_position, TriggerType &trigger, pframes_t(TriggerType::*run_method)(BufferSet &bufs, samplepos_t start_sample, samplepos_t end_sample, Temporal::Beats const &start_beats, Temporal::Beats const &end_beats, pframes_t nframes, pframes_t dest_offset, double bpm, pframes_t &), uint32_t cnt)
bool explicitly_stopped() const
Definition: triggerbox.h:380
TriggerBox & _box
Definition: triggerbox.h:448
bool _explicitly_stopped
Definition: triggerbox.h:458
PBD::Property< bool > _allow_patch_changes
Definition: triggerbox.h:164
double _segment_tempo
Definition: triggerbox.h:476
std::atomic< unsigned int > last_property_generation
Definition: triggerbox.h:494
virtual void tempo_map_changed()
Definition: triggerbox.h:287
void startup(BufferSet &, pframes_t dest_offset, Temporal::BBT_Offset const &start_quantization=Temporal::BBT_Offset(9, 3, 0))
bool internal_use_follow_length() const
bool is_set() const
Definition: PatchChange.h:110
std::bitset< 16 > UsedChannels
Definition: SMF.h:109
Definition: id.h:33
std::shared_ptr< TempoMap const > SharedPtr
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
PBD::PropertyDescriptor< uint32_t > queued
PBD::PropertyDescriptor< gain_t > gain
PBD::PropertyDescriptor< bool > legato
PBD::PropertyDescriptor< bool > tempo_meter
PBD::PropertyDescriptor< Temporal::BBT_Offset > follow_length
PBD::PropertyDescriptor< bool > use_follow_length
PBD::PropertyDescriptor< bool > running
PBD::PropertyDescriptor< Trigger::LaunchStyle > launch_style
PBD::PropertyDescriptor< uint32_t > color
PBD::PropertyDescriptor< uint32_t > currently_playing
PBD::PropertyDescriptor< int > follow_action_probability
PBD::PropertyDescriptor< bool > allow_patch_changes
PBD::PropertyDescriptor< timecnt_t > length
PBD::PropertyDescriptor< bool > cue_isolated
PBD::PropertyDescriptor< Temporal::BBT_Offset > quantization
PBD::PropertyDescriptor< bool > region
PBD::PropertyDescriptor< bool > patch_change
PBD::PropertyDescriptor< FollowAction > follow_action1
PBD::PropertyDescriptor< timepos_t > start
PBD::PropertyDescriptor< float > velocity_effect
PBD::PropertyDescriptor< FollowAction > follow_action0
PBD::PropertyDescriptor< Temporal::BBT_Offset > capture_duration
PBD::PropertyDescriptor< uint32_t > follow_count
PBD::PropertyDescriptor< bool > stretchable
PBD::PropertyDescriptor< bool > used_channels
PBD::PropertyDescriptor< Trigger::StretchMode > stretch_mode
PBD::PropertyDescriptor< bool > channel_map
PBD::RingBuffer< CueRecord > CueRecords
Definition: triggerbox.h:819
std::shared_ptr< Trigger > TriggerPtr
Definition: triggerbox.h:82
uint32_t pframes_t
std::vector< CueEvent > CueEvents
Temporal::samplecnt_t samplecnt_t
uint32_t color_t
Definition: triggerbox.h:76
RTMidiBufferBase< Temporal::Beats, Temporal::Beats > RTMidiBufferBeats
Definition: triggerbox.h:85
std::string cue_marker_name(int32_t)
Temporal::samplepos_t samplepos_t
void flush()
DebugBits Properties
Definition: axis_view.h:42
DEFINE_ENUM_CONVERT(ARDOUR::DSP::PerceptualAnalyzer::Speed)
samplecnt_t append(Sample const *src, samplecnt_t cnt, uint32_t chan)
void alloc(samplecnt_t cnt, uint32_t nchans)
int32_t cue_number
Definition: triggerbox.h:810
static const int32_t stop_all
Definition: triggerbox.h:816
CueRecord(int32_t cn, samplepos_t t)
Definition: triggerbox.h:813
samplepos_t when
Definition: triggerbox.h:811
RTMidiBufferBeats * rt_midibuffer
Definition: triggerbox.h:736
Temporal::Beats end_beats
Definition: triggerbox.h:830
MidiNoteTracker tracker
Definition: triggerbox.h:833
AudioTrigger::AudioData audio_buf
Definition: triggerbox.h:835
void reset(Trigger &)
samplepos_t end_samples
Definition: triggerbox.h:831
Temporal::Beats start_beats
Definition: triggerbox.h:828
samplecnt_t captured
Definition: triggerbox.h:832
samplepos_t start_samples
Definition: triggerbox.h:829
RTMidiBufferBeats * midi_buf
Definition: triggerbox.h:834
RubberBand::RubberBandStretcher * stretcher
Definition: triggerbox.h:836
Temporal::timecnt_t duration
Definition: triggerbox.h:788
static PBD::MultiAllocSingleReleasePool * pool
Definition: triggerbox.h:794
std::shared_ptr< Region > region
Definition: triggerbox.h:785
Temporal::timepos_t position
Definition: triggerbox.h:789
static PBD::MultiAllocSingleReleasePool * pool
Definition: triggerbox.h:1070
std::atomic< bool > stop_all
Definition: triggerbox.h:1006
std::atomic< bool > stop
Definition: triggerbox.h:440
Temporal::BBT_Offset quantization
Definition: triggerbox.h:184
Temporal::BBT_Offset follow_length
Definition: triggerbox.h:185
Temporal::BBT_Offset capture_duration
Definition: triggerbox.h:186
StretchMode stretch_mode
Definition: triggerbox.h:194
LaunchStyle launch_style
Definition: triggerbox.h:179
FollowAction follow_action0
Definition: triggerbox.h:180
std::atomic< unsigned int > generation
Definition: triggerbox.h:177
Evoral::SMF::UsedChannels used_channels
Definition: triggerbox.h:196
Evoral::PatchChange< MidiBuffer::TimeType > patch_change[16]
Definition: triggerbox.h:197
FollowAction follow_action1
Definition: triggerbox.h:181
#define TRIGGERBOX_PROPERTY_DECL_CONST_REF(name, type)
Definition: triggerbox.h:244
#define TRIGGERBOX_PROPERTY_DECL(name, type)
Definition: triggerbox.h:243