BEAST - Free Software Audio Synthesizer and Tracker  0.10.0
bsepart.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __BSE_PART_H__
3 #define __BSE_PART_H__
4 
5 #include <bse/bseitem.hh>
6 #include <sfi/gbsearcharray.hh>
7 
8 G_BEGIN_DECLS
9 
10 /* --- object type macros --- */
11 #define BSE_TYPE_PART (BSE_TYPE_ID (BsePart))
12 #define BSE_PART(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), BSE_TYPE_PART, BsePart))
13 #define BSE_PART_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), BSE_TYPE_PART, BsePartClass))
14 #define BSE_IS_PART(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), BSE_TYPE_PART))
15 #define BSE_IS_PART_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), BSE_TYPE_PART))
16 #define BSE_PART_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), BSE_TYPE_PART, BsePartClass))
17 
18 
19 /* --- typedefs & structures --- */
21  GBSearchArray *bsa;
22 };
24  GBSearchArray *bsa;
25 };
26 struct BsePart : BseItem {
27  const double *semitone_table; // [-132..+132] only updated when not playing
28  /* id -> tick lookups */
29  guint n_ids;
30  guint *ids;
31  guint last_id; /* head of free id list */
32  /* control events */
33  BsePartControls controls;
34  /* notes */
35  guint n_channels;
36  BsePartNoteChannel *channels;
37  /* one after any tick used by controls or notes */
38  guint last_tick_SL;
39  /* queued updates */
40  guint links_queued : 1;
41  guint range_queued : 1;
42  guint range_tick;
43  guint range_bound;
44  gint range_min_note;
45  gint range_max_note;
46 };
48  void (*range_changed) (BsePart *part,
49  guint tick,
50  guint duration,
51  gint range_min_note,
52  gint range_max_note);
53 };
54 typedef enum /*< skip >*/
55 {
56  BSE_PART_EVENT_NONE,
57  BSE_PART_EVENT_CONTROL,
58  BSE_PART_EVENT_NOTE
59 } BsePartEventType;
60 
61 #define bse_part_transpose_factor( part, index /* -132..+132*/) ((part)->semitone_table[index])
62 void bse_part_set_semitone_table (BsePart *self,
63  const double *semitone_table);
64 void bse_part_links_changed (BsePart *self);
65 Bse::PartLinkSeq bse_part_list_links (BsePart *self);
66 gboolean bse_part_delete_control (BsePart *self,
67  guint id);
68 gboolean bse_part_delete_note (BsePart *self,
69  guint id,
70  guint channel);
71 guint bse_part_insert_note (BsePart *self,
72  guint channel,
73  guint tick,
74  guint duration,
75  gint note,
76  gint fine_tune,
77  gfloat velocity);
78 guint bse_part_insert_control (BsePart *self,
79  guint tick,
80  Bse::MidiSignal ctype,
81  gfloat value);
82 gboolean bse_part_change_note (BsePart *self,
83  guint id,
84  guint channel,
85  guint tick,
86  guint duration,
87  gint note,
88  gint fine_tune,
89  gfloat velocity);
90 gboolean bse_part_change_control (BsePart *self,
91  guint id,
92  guint tick,
93  Bse::MidiSignal ctype,
94  gfloat value);
95 Bse::PartNoteSeq bse_part_list_notes (BsePart *self,
96  guint channel,
97  guint tick,
98  guint duration,
99  gint min_note,
100  gint max_note,
101  gboolean include_crossings);
102 Bse::PartControlSeq bse_part_list_controls (BsePart *self,
103  guint channel, /* for note events */
104  guint tick,
105  guint duration,
106  Bse::MidiSignal ctype);
107 void bse_part_queue_notes_within (BsePart *self,
108  guint tick,
109  guint duration,
110  gint min_note,
111  gint max_note);
112 #define bse_part_queue_controls(p,t,d) bse_part_queue_notes_within (p, t, d, BSE_MIN_NOTE, BSE_MAX_NOTE)
113 Bse::PartNoteSeq bse_part_list_selected_notes (BsePart *self);
114 Bse::PartControlSeq bse_part_list_selected_controls (BsePart *self, Bse::MidiSignal ctype);
115 void bse_part_select_notes (BsePart *self,
116  guint channel,
117  guint tick,
118  guint duration,
119  gint min_note,
120  gint max_note,
121  gboolean selected);
122 void bse_part_select_controls (BsePart *self,
123  guint tick,
124  guint duration,
125  Bse::MidiSignal ctype,
126  gboolean selected);
127 void bse_part_select_notes_exclusive (BsePart *self,
128  guint channel,
129  guint tick,
130  guint duration,
131  gint min_note,
132  gint max_note);
133 void bse_part_select_controls_exclusive (BsePart *self,
134  guint tick,
135  guint duration,
136  Bse::MidiSignal ctype);
137 gboolean bse_part_set_note_selected (BsePart *self,
138  guint id,
139  guint channel,
140  gboolean selected);
141 gboolean bse_part_set_control_selected (BsePart *self,
142  guint id,
143  gboolean selected);
145  guint id;
146  BsePartEventType event_type;
147  guint channel;
148  guint tick;
149  gboolean selected;
150  /* note */
151  guint duration;
152  gint note;
153  gint fine_tune;
154  gfloat velocity;
155  /* note control */
156  gfloat fine_tune_value;
157  gfloat velocity_value;
158  /* control */
159  Bse::MidiSignal control_type;
160  gfloat control_value;
161 };
162 
163 BsePartEventType bse_part_query_event (BsePart *self,
164  guint id,
165  BsePartQueryEvent *equery);
166 
167 
168 /* --- implementation details --- */
169 #define BSE_PART_MAX_CHANNELS (0x1024)
170 #define BSE_PART_MAX_TICK (0x7fffffff)
171 #define BSE_PART_INVAL_TICK_FLAG (0x80000000)
172 #define BSE_PART_NOTE_CONTROL(ctype) ((ctype) == Bse::MidiSignal::VELOCITY || \
173  (ctype) == Bse::MidiSignal::FINE_TUNE)
174 
175 /* --- BsePartControlChannel --- */
176 struct BsePartEventControl;
178  guint tick;
179  BsePartEventControl *events;
180 };
182  BsePartEventControl *next;
183  guint id : 31;
184  guint selected : 1;
185  guint ctype; /* Bse::MidiSignal */
186  gfloat value; /* -1 .. 1 */
187 };
188 
189 void bse_part_controls_init (BsePartControls *self);
190 BsePartTickNode* bse_part_controls_lookup (BsePartControls *self,
191  guint tick);
192 BsePartEventControl* bse_part_controls_lookup_event (BsePartControls *self,
193  guint tick,
194  guint id);
195 BsePartTickNode* bse_part_controls_lookup_ge (BsePartControls *self,
196  guint tick);
197 BsePartTickNode* bse_part_controls_lookup_lt (BsePartControls *self,
198  guint tick);
199 BsePartTickNode* bse_part_controls_lookup_le (BsePartControls *self,
200  guint tick);
201 BsePartTickNode* bse_part_controls_get_bound (BsePartControls *self);
202 guint bse_part_controls_get_last_tick (BsePartControls *self);
203 BsePartTickNode* bse_part_controls_ensure_tick (BsePartControls *self,
204  guint tick);
205 void bse_part_controls_insert (BsePartControls *self,
206  BsePartTickNode *node,
207  guint id,
208  guint selected,
209  guint ctype,
210  gfloat value);
211 void bse_part_controls_change (BsePartControls *self,
212  BsePartTickNode *node,
213  BsePartEventControl *cev,
214  guint id,
215  guint selected,
216  guint ctype,
217  gfloat value);
218 void bse_part_controls_change_selected (BsePartEventControl *cev,
219  guint selected);
220 void bse_part_controls_remove (BsePartControls *self,
221  guint tick,
222  BsePartEventControl *cev);
223 void bse_part_controls_destroy (BsePartControls *self);
224 
226  guint tick;
227  guint id : 31;
228  guint selected : 1;
229  guint *crossings;
230  guint duration; /* in ticks */
231  gint note;
232  gint fine_tune;
233  gfloat velocity; /* 0 .. 1 */
234 };
235 
236 #define BSE_PART_NOTE_N_CROSSINGS(note) ((note)->crossings ? (note)->crossings[0] : 0)
237 #define BSE_PART_NOTE_CROSSING(note,j) ((note)->crossings[1 + (j)])
238 #define BSE_PART_SEMITONE_FACTOR(part,noteval) (bse_part_transpose_factor ((part), CLAMP ((noteval), SFI_MIN_NOTE, SFI_MAX_NOTE) - SFI_KAMMER_NOTE))
239 #define BSE_PART_NOTE_FREQ(part,note) (BSE_KAMMER_FREQUENCY * \
240  BSE_PART_SEMITONE_FACTOR ((part), (note)->note) * \
241  bse_cent_tune_fast ((note)->fine_tune))
242 
243 void bse_part_note_channel_init (BsePartNoteChannel *self);
244 BsePartEventNote* bse_part_note_channel_lookup (BsePartNoteChannel *self,
245  guint tick);
246 BsePartEventNote* bse_part_note_channel_lookup_le (BsePartNoteChannel *self,
247  guint tick);
248 BsePartEventNote* bse_part_note_channel_lookup_lt (BsePartNoteChannel *self,
249  guint tick);
250 BsePartEventNote* bse_part_note_channel_lookup_ge (BsePartNoteChannel *self,
251  guint tick);
252 BsePartEventNote* bse_part_note_channel_get_bound (BsePartNoteChannel *self);
253 guint bse_part_note_channel_get_last_tick (BsePartNoteChannel *self);
254 BsePartEventNote* bse_part_note_channel_insert (BsePartNoteChannel *self,
255  BsePartEventNote key);
256 void bse_part_note_channel_change_note (BsePartNoteChannel *self,
257  BsePartEventNote *note,
258  guint id,
259  gboolean selected,
260  gint vnote,
261  gint fine_tune,
262  gfloat velocity);
263 void bse_part_note_channel_remove (BsePartNoteChannel *self,
264  guint tick);
265 void bse_part_note_channel_destroy (BsePartNoteChannel *self);
266 
267 G_END_DECLS
268 
269 namespace Bse {
270 
271 class PartImpl : public ItemImpl, public virtual PartIface {
272 protected:
273  virtual ~PartImpl ();
274 public:
275  explicit PartImpl (BseObject*);
276  virtual PartNoteSeq list_notes_crossing (int tick, int duration) override;
277  virtual PartNoteSeq list_notes_within (int channel, int tick, int duration) override;
278  virtual PartNoteSeq list_selected_notes () override;
279  virtual PartNoteSeq check_overlap (int tick, int duration, int note) override;
280  virtual PartNoteSeq get_notes (int tick, int note) override;
281  virtual PartControlSeq list_selected_controls (MidiSignal control_type) override;
282  virtual PartControlSeq list_controls (int tick, int duration, MidiSignal control_type) override;
283  virtual PartControlSeq get_channel_controls (int channel, int tick, int duration, MidiSignal control_type) override;
284  virtual PartControlSeq get_controls (int tick, MidiSignal control_type) override;
285  virtual PartLinkSeq list_links () override;
286  virtual SongTiming get_timing (int tick) override;
287  virtual int get_max_note () override;
288  virtual int get_min_note () override;
289  virtual Error change_control (int id, int tick, MidiSignal control_type, double value) override;
290  virtual Error change_note (int id, int tick, int duration, int note, int fine_tune, double velocity) override;
291  virtual Error delete_event (int id) override;
292  virtual void deselect_controls (int tick, int duration, MidiSignal control_type) override;
293  virtual void deselect_event (int id) override;
294  virtual void deselect_notes (int tick, int duration, int min_note, int max_note) override;
295  virtual bool is_event_selected (int id) override;
296  virtual void select_controls (int tick, int duration, MidiSignal control_type) override;
297  virtual void select_controls_exclusive (int tick, int duration, MidiSignal control_type) override;
298  virtual void select_event (int id) override;
299  virtual void select_notes (int tick, int duration, int min_note, int max_note) override;
300  virtual void select_notes_exclusive (int tick, int duration, int min_note, int max_note) override;
301  virtual int insert_control (int tick, MidiSignal control_type, double value) override;
302  virtual int insert_note (int channel, int tick, int duration, int note, int fine_tune, double velocity) override;
303  virtual int insert_note_auto (int tick, int duration, int note, int fine_tune, double velocity) override;
304  virtual void queue_controls (int tick, int duration) override;
305  virtual void queue_notes (int tick, int duration, int min_note, int max_note) override;
306 };
307 
308 } // Bse
309 
310 
311 #endif /* __BSE_PART_H__ */
virtual int insert_note(int channel, int tick, int duration, int note, int fine_tune, double velocity) override
See Part::insert_note()
Definition: bsepart.cc:2359
The Bse namespace contains all functions of the synthesis engine.
Definition: bstbseutils.cc:88
Definition: bsepart.hh:23
Definition: bsepart.hh:181
virtual Error delete_event(int id) override
See Part::delete_event()
Definition: bsepart.cc:2248
virtual int insert_note_auto(int tick, int duration, int note, int fine_tune, double velocity) override
See Part::insert_note_auto()
Definition: bsepart.cc:2369
virtual int get_max_note() override
See Part::get_max_note()
Definition: bsepart.cc:2171
virtual int get_min_note() override
See Part::get_min_note()
Definition: bsepart.cc:2177
virtual PartControlSeq get_controls(int tick, MidiSignal control_type) override
See Part::get_controls()
Definition: bsepart.cc:2137
Definition: bsepart.hh:144
virtual PartControlSeq get_channel_controls(int channel, int tick, int duration, MidiSignal control_type) override
See Part::get_channel_controls()
Definition: bsepart.cc:2144
virtual void select_controls_exclusive(int tick, int duration, MidiSignal control_type) override
See Part::select_controls_exclusive()
Definition: bsepart.cc:2316
virtual PartControlSeq list_selected_controls(MidiSignal control_type) override
See Part::list_selected_controls()
Definition: bsepart.cc:2130
virtual void deselect_controls(int tick, int duration, MidiSignal control_type) override
See Part::deselect_controls()
Definition: bsepart.cc:2272
Definition: bsepart.hh:225
virtual PartNoteSeq check_overlap(int tick, int duration, int note) override
See Part::check_overlap()
Definition: bsepart.cc:2109
virtual int insert_control(int tick, MidiSignal control_type, double value) override
See Part::insert_control()
Definition: bsepart.cc:2349
virtual void select_notes_exclusive(int tick, int duration, int min_note, int max_note) override
See Part::select_notes_exclusive()
Definition: bsepart.cc:2342
Definition: gbsearcharray.hh:37
virtual SongTiming get_timing(int tick) override
See Part::get_timing()
Definition: bsepart.cc:2158
Definition: bsepart.hh:47
A list of part control events.
Definition: bseapi.idl:527
Definition: bsepart.hh:271
Definition: bsepart.hh:20
virtual void queue_notes(int tick, int duration, int min_note, int max_note) override
See Part::queue_notes()
Definition: bsepart.cc:2386
virtual Error change_control(int id, int tick, MidiSignal control_type, double value) override
See Part::change_control()
Definition: bsepart.cc:2183
Definition: bseobject.hh:61
virtual PartLinkSeq list_links() override
See Part::list_links()
Definition: bsepart.cc:2151
virtual void queue_controls(int tick, int duration) override
See Part::queue_controls()
Definition: bsepart.cc:2379
virtual bool is_event_selected(int id) override
See Part::is_event_selected()
Definition: bsepart.cc:2298
virtual void deselect_event(int id) override
See Part::deselect_event()
Definition: bsepart.cc:2279
See also the corresponding IDL class Part.
Definition: bseserverapi.hh:777
virtual PartNoteSeq get_notes(int tick, int note) override
See Part::get_notes()
Definition: bsepart.cc:2116
virtual PartNoteSeq list_notes_crossing(int tick, int duration) override
See Part::list_notes_crossing()
Definition: bsepart.cc:2088
virtual void select_notes(int tick, int duration, int min_note, int max_note) override
See Part::select_notes()
Definition: bsepart.cc:2335
A list of part note events.
Definition: bseapi.idl:513
virtual PartNoteSeq list_selected_notes() override
See Part::list_selected_notes()
Definition: bsepart.cc:2102
virtual void deselect_notes(int tick, int duration, int min_note, int max_note) override
See Part::deselect_notes()
Definition: bsepart.cc:2291
Definition: bseitem.hh:152
Definition: bseitem.hh:39
Definition: bsepart.hh:177
Song timing configuration.
Definition: bseapi.idl:428
Definition: bsepart.hh:26
virtual void select_event(int id) override
See Part::select_event()
Definition: bsepart.cc:2323
virtual PartControlSeq list_controls(int tick, int duration, MidiSignal control_type) override
See Part::list_controls()
Definition: bsepart.cc:2123
virtual Error change_note(int id, int tick, int duration, int note, int fine_tune, double velocity) override
See Part::change_note()
Definition: bsepart.cc:2223
Sequence of PartLink records.
Definition: bseapi.idl:698
Definition: bseitem.hh:34
virtual void select_controls(int tick, int duration, MidiSignal control_type) override
See Part::select_controls()
Definition: bsepart.cc:2309
virtual PartNoteSeq list_notes_within(int channel, int tick, int duration) override
See Part::list_notes_within()
Definition: bsepart.cc:2095