Anklang 0.3.0-460-gc4ef46ba
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#ifndef __ASE_CLIP_HH__
3#define __ASE_CLIP_HH__
4
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 {
17public:
18 struct CmpNoteTicks { int operator() (const ClipNote &a, const ClipNote &b) const; };
19 struct CmpNoteIds { int operator() (const ClipNote &a, const ClipNote &b) const; };
21private:
22 int64 starttick_ = 0, stoptick_ = 0, endtick_ = 0;
23 EventsById notes_;
24 Connection notifytrack_;
26 struct EventImage {
27 String cbuffer;
29 EventImage (const ClipNoteS &clipnotes);
30 ~EventImage();
31 };
32 using EventImageP = std::shared_ptr<EventImage>;
33 void apply_undo (const EventImage &image, const String &undogroup);
34 static size_t collapse_notes (EventsById &notes, bool preserve_selected);
35public:
36 class Generator;
37protected:
38 TrackImpl *track_ = nullptr;
39 Connection ontrackchange_;
40 explicit ClipImpl (TrackImpl &parent);
41 virtual ~ClipImpl ();
42 void serialize (WritNode &xs) override;
43 ssize_t clip_index () const;
44 ClipNoteS get_all_notes () const override;
45 void set_all_notes (const ClipNoteS &notes) override;
46 int64 get_end_tick () const override;
47 void set_end_tick (int64 etick) override;
48public:
49 using OrderedEventsP = OrderedEventsV::ConstP;
50 OrderedEventsP tick_events () const;
51 ProjectImpl* project () const;
52 void push_undo (const ClipNoteS &clipnotes, const String &undogroup);
53 UndoScope undo_scope (const String &scopename) { return project()->undo_scope (scopename); }
54 int64 start_tick () const override { return starttick_; }
55 int64 stop_tick () const override { return stoptick_; }
56 void assign_range (int64 starttick, int64 stoptick) override;
57 ClipNoteS list_all_notes () override;
58 bool needs_serialize() const;
59 int32 change_batch (const ClipNoteS &notes, const String &undogroup) override;
61};
62
66 int64 last_ = I63MAX;
67 int64 xtick_ = 0; // external tick (API)
68 int64 itick_ = 0; // internal tick (clip position)
69 int64 start_offset_ = 0;
70 int64 loop_start_ = 0;
71 int64 loop_end_ = I63MAX;
72 EventS events_;
73 bool muted_ = false;
74 friend class ClipImpl;
75public:
77 using Receiver = std::function<void (int64 tick, MidiEvent &event)>;
78 explicit Generator () = default;
79 void setup (const ClipImpl &clip);
80 void jumpto (int64 target_tick);
81 int64 generate (int64 target_tick, const Receiver &receiver);
83 bool muted () const { return muted_; }
85 void muted (bool b) { muted_ = b; }
87 int64 start_offset () const { return start_offset_; }
89 int64 loop_start () const { return loop_start_; }
91 int64 loop_end () const { return loop_end_; }
93 int64 play_length () const { return last_; }
95 int64 play_position () const { return xtick_; }
97 bool done () const { return play_position() >= play_length(); }
99 int64 clip_position () const { return itick_; }
100};
102
103
104// == Implementation Details ==
105inline int
106ClipImpl::CmpNoteIds::operator () (const ClipNote &a, const ClipNote &b) const
107{
108 return Aux::compare_lesser (a.id, b.id);
109}
110
111inline int
112ClipImpl::CmpNoteTicks::operator() (const ClipNote &a, const ClipNote &b) const
113{
114 // tick is neccessary primary key for playback
115 const int tcmp = Aux::compare_lesser (a.tick, b.tick);
116 if (ASE_ISLIKELY (tcmp))
117 return tcmp;
118 const int kcmp = Aux::compare_lesser (a.key, b.key);
119 if (ASE_ISLIKELY (kcmp))
120 return kcmp;
121 const int ccmp = Aux::compare_lesser (a.channel, b.channel);
122 if (ASE_ISLIKELY (ccmp))
123 return ccmp;
124 // allow selected to "override" a previous unselected element
125 const int scmp = Aux::compare_lesser (a.selected, b.selected);
126 if (ASE_UNLIKELY (scmp))
127 return scmp;
128 return Aux::compare_lesser (a.id, b.id);
129}
130
131String stringify_clip_note (const ClipNote &n);
132
133} // Ase
134
135#endif // __ASE_CLIP_HH__
Generator for MIDI events.
Definition clip.hh:64
void setup(const ClipImpl &clip)
Create generator from clip.
Definition clip.cc:302
bool muted() const
Mute MIDI note generation.
Definition clip.hh:83
bool done() const
Check if playback is done.
Definition clip.hh:97
int64 clip_position() const
Position within clip as tick.
Definition clip.hh:99
int64 loop_start() const
Loop start in ticks.
Definition clip.hh:89
int64 generate(int64 target_tick, const Receiver &receiver)
Advance tick and call receiver for generated events.
Definition clip.cc:360
int64 start_offset() const
Initial offset in ticks.
Definition clip.hh:87
void jumpto(int64 target_tick)
Assign new play_position() (and clip_position()), preserves all other state.
Definition clip.cc:321
int64 play_position() const
Current playback position in ticks.
Definition clip.hh:95
void muted(bool b)
Assign muted state.
Definition clip.hh:85
int64 play_length() const
Maximum amount of ticks during playback.
Definition clip.hh:93
int64 loop_end() const
Loop end in ticks.
Definition clip.hh:91
void assign_range(int64 starttick, int64 stoptick) override
Definition clip.cc:116
int64 start_tick() const override
Get the first tick intended for playback (this is >= 0), changes on notify:start_tick.
Definition clip.hh:54
ClipNoteS list_all_notes() override
Definition clip.cc:135
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:247
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.hh:55
void serialize(WritNode &xs) override
Serialize members and childern.
Definition clip.cc:66
OrderedEventsP tick_events() const
Retrieve const vector with all notes ordered by tick.
Definition clip.cc:174
Container for MIDI note and control events.
Definition api.hh:264
Base type for classes that have a Property.
Definition gadget.hh:12
Ase::Track implementation.
Definition track.hh:10
One entry in a Writ serialization document.
Definition serialize.hh:24
#define ASE_DEFINE_MAKE_SHARED(CLASS)
Definition cxxaux.hh:269
#define ASE_UNLIKELY(expr)
Compiler hint to optimize for expr evaluating to false.
Definition cxxaux.hh:46
#define ASE_ISLIKELY(expr)
Compiler hint to optimize for expr evaluating to true.
Definition cxxaux.hh:45
The Anklang C++ API namespace.
Definition api.hh:9
int32_t int32
A 32-bit signed integer.
Definition cxxaux.hh:28
int64_t int64
A 64-bit unsigned integer, use PRI*64 in format strings.
Definition cxxaux.hh:29
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:35
uint32_t uint
Provide 'uint' as convenience type.
Definition cxxaux.hh:18
Part specific note event representation.
Definition api.hh:251
MidiEvent data structure.
Definition midievent.hh:50
Container for a sorted array of opaque Event structures with binary lookup.
Definition eventlist.hh:13
typedef ssize_t