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