Anklang-0.3.0.dev956+gd75ac925 anklang-0.3.0.dev956+gd75ac925
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
clip.hh
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#pragma once
3
4#include <ase/trkn-utils.hh>
5#include <ase/project.hh>
6#include <ase/eventlist.hh>
7#include <ase/midievent.hh>
8
9namespace Ase {
10
12constexpr const uint MIDI_NOTE_ID_FIRST = 0x10000001;
14constexpr const uint MIDI_NOTE_ID_LAST = 0xfffffffe;
15
16class ClipImpl : public GadgetImpl, public virtual Clip {
17 friend class TrackImpl;
18public:
19 struct CmpNoteTicks { int operator() (const ClipNote &a, const ClipNote &b) const; };
21private:
25public:
26 class Generator;
27protected:
28 explicit ClipImpl (tracktion::Clip &clip);
29 virtual ~ClipImpl ();
30 ssize_t clip_index () const;
31 ClipNoteS all_notes () const override;
32 void all_notes (const ClipNoteS &notes) override;
33 int64 end_tick () const override;
34 void end_tick (int64 etick) override;
35public:
38 ProjectImpl* project () const;
39 int64 start_tick () const override;
40 int64 stop_tick () const override;
41 void assign_range (int64 starttick, int64 stoptick) override;
42 ClipNoteS list_all_notes () override;
43 int32 change_batch (const ClipNoteS &notes, const String &undogroup) override;
44 bool is_muted () const override;
45 void set_muted (bool muted) override;
46 double volume () const override;
47 void volume (double db) override;
48 double pan () const override;
49 void pan (double pan) override;
50 void update_telemetry ();
51 void remove_self () override;
52 TelemetryFieldS telemetry () const override;
53 static ClipImplP from_trkn (tracktion::Clip&);
55};
56
60 int64 last_ = I63MAX;
61 int64 xtick_ = 0; // external tick (API)
62 int64 itick_ = 0; // internal tick (clip position)
63 int64 start_offset_ = 0;
64 int64 loop_start_ = 0;
65 int64 loop_end_ = I63MAX;
66 EventS events_;
67 bool muted_ = false;
68 friend class ClipImpl;
69public:
71 using Receiver = std::function<void (int64 tick, MidiEvent &event)>;
72 explicit Generator () = default;
73 void setup (const ClipImpl &clip);
74 void jumpto (int64 target_tick);
75 int64 generate (int64 target_tick, const Receiver &receiver);
77 bool muted () const { return muted_; }
79 void muted (bool b) { muted_ = b; }
81 int64 start_offset () const { return start_offset_; }
83 int64 loop_start () const { return loop_start_; }
85 int64 loop_end () const { return loop_end_; }
87 int64 play_length () const { return last_; }
89 int64 play_position () const { return xtick_; }
91 bool done () const { return play_position() >= play_length(); }
93 int64 clip_position () const { return itick_; }
94};
96
97
98// == Implementation Details ==
99inline int
100ClipImpl::CmpNoteTicks::operator() (const ClipNote &a, const ClipNote &b) const
101{
102 // tick is neccessary primary key for playback
103 const int tcmp = Aux::compare_lesser (a.tick, b.tick);
104 if (ASE_ISLIKELY (tcmp))
105 return tcmp;
106 const int kcmp = Aux::compare_lesser (a.key, b.key);
107 if (ASE_ISLIKELY (kcmp))
108 return kcmp;
109 const int ccmp = Aux::compare_lesser (a.channel, b.channel);
110 if (ASE_ISLIKELY (ccmp))
111 return ccmp;
112 // allow selected to "override" a previous unselected element
113 const int scmp = Aux::compare_lesser (a.selected, b.selected);
114 if (ASE_UNLIKELY (scmp))
115 return scmp;
116 return Aux::compare_lesser (a.id, b.id);
117}
118
119String stringify_clip_note (const ClipNote &n);
120
121} // Ase
122
Generator for MIDI events.
Definition clip.hh:58
void setup(const ClipImpl &clip)
Create generator from clip.
Definition clip.cc:376
bool muted() const
Mute MIDI note generation.
Definition clip.hh:77
bool done() const
Check if playback is done.
Definition clip.hh:91
int64 clip_position() const
Position within clip as tick.
Definition clip.hh:93
int64 loop_start() const
Loop start in ticks.
Definition clip.hh:83
int64 generate(int64 target_tick, const Receiver &receiver)
Advance tick and call receiver for generated events.
Definition clip.cc:432
int64 start_offset() const
Initial offset in ticks.
Definition clip.hh:81
void jumpto(int64 target_tick)
Assign new play_position() (and clip_position()), preserves all other state.
Definition clip.cc:393
int64 play_position() const
Current playback position in ticks.
Definition clip.hh:89
void muted(bool b)
Assign muted state.
Definition clip.hh:79
int64 play_length() const
Maximum amount of ticks during playback.
Definition clip.hh:87
int64 loop_end() const
Loop end in ticks.
Definition clip.hh:85
void set_muted(bool muted) override
Set clip muted state, emits notify:muted.
Definition clip.cc:223
void assign_range(int64 starttick, int64 stoptick) override
Change start_tick() and stop_tick(); emits notify:start_tick, notify:stop_tick.
Definition clip.cc:114
int64 start_tick() const override
Get the first tick intended for playback (this is >= 0), changes on notify:start_tick.
Definition clip.cc:200
ClipNoteS list_all_notes() override
List all notes of this Clip; changes on notify:notes.
Definition clip.cc:141
int32 change_batch(const ClipNoteS &notes, const String &undogroup) override
Change note id according to the arguments or add a new note if id < 0; emits notify:notes.
Definition clip.cc:317
double volume() const override
Get clip volume in dB.
Definition clip.cc:232
bool is_muted() const override
Check if clip is muted.
Definition clip.cc:216
int64 stop_tick() const override
Get the tick to stop playback, not events should be played after this, changes on notify:stop_tick.
Definition clip.cc:208
TelemetryFieldS telemetry() const override
Retrieve clip telemetry locations.
Definition clip.cc:283
double pan() const override
Get clip pan (-1.0 to 1.0).
Definition clip.cc:262
OrderedEventsP tick_events() const
Retrieve const vector with all notes ordered by tick.
Definition clip.cc:310
void remove_self() override
Remove self from parent container.
Definition clip.cc:295
Container for MIDI note and control events.
Definition api.hh:240
Base type for classes that have a Property.
Definition gadget.hh:11
Mimick tracktion::engine::SafeSelectable<> for tracktion::Selectable descendants.
Definition trkn-utils.hh:27
Ase::Track implementation.
Definition track.hh:10
#define ASE_DEFINE_MAKE_SHARED(CLASS)
Define a member function static shared_ptr<CLASS> make_shared(ctorargs...);.
Definition cxxaux.hh:274
#define ASE_UNLIKELY(expr)
Compiler hint to optimize for expr evaluating to false.
Definition cxxaux.hh:45
#define ASE_ISLIKELY(expr)
Compiler hint to optimize for expr evaluating to true.
Definition cxxaux.hh:44
The Anklang C++ API namespace.
Definition api.hh:8
int32_t int32
A 32-bit signed integer.
Definition cxxaux.hh:27
int64_t int64
A 64-bit unsigned integer, use PRI*64 in format strings.
Definition cxxaux.hh:28
constexpr const uint MIDI_NOTE_ID_LAST
Last valid (internal) MIDI note event ID.
Definition clip.hh:14
constexpr const uint MIDI_NOTE_ID_FIRST
First (internal) MIDI note event ID (lower IDs are reserved for external notes).
Definition clip.hh:12
std::string String
Convenience alias for std::string.
Definition cxxaux.hh:34
uint32_t uint
Provide 'uint' as convenience type.
Definition cxxaux.hh:17
Part specific note event representation.
Definition api.hh:227
int64 tick
UI selection flag.
Definition api.hh:232
bool selected
Musical note as MIDI key, 0 .. 127.
Definition api.hh:231
int8 channel
ID, > 0.
Definition api.hh:229
int8 key
MIDI Channel.
Definition api.hh:230
MidiEvent data structure.
Definition midievent.hh:49
Container for a sorted array of opaque Event structures with binary lookup.
Definition eventlist.hh:12
typedef ssize_t