BEAST/BSE - Better Audio System and Sound Engine  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 BsePartLinkSeq* 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  BseMidiSignalType 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  BseMidiSignalType ctype,
94  gfloat value);
95 BsePartNoteSeq* 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 BsePartControlSeq* bse_part_list_controls (BsePart *self,
103  guint channel, /* for note events */
104  guint tick,
105  guint duration,
106  BseMidiSignalType 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 BsePartNoteSeq* bse_part_list_selected_notes (BsePart *self);
114 BsePartControlSeq* bse_part_list_selected_controls (BsePart *self,
115  BseMidiSignalType ctype);
116 void bse_part_select_notes (BsePart *self,
117  guint channel,
118  guint tick,
119  guint duration,
120  gint min_note,
121  gint max_note,
122  gboolean selected);
123 void bse_part_select_controls (BsePart *self,
124  guint tick,
125  guint duration,
126  BseMidiSignalType ctype,
127  gboolean selected);
128 void bse_part_select_notes_exclusive (BsePart *self,
129  guint channel,
130  guint tick,
131  guint duration,
132  gint min_note,
133  gint max_note);
134 void bse_part_select_controls_exclusive (BsePart *self,
135  guint tick,
136  guint duration,
137  BseMidiSignalType ctype);
138 gboolean bse_part_set_note_selected (BsePart *self,
139  guint id,
140  guint channel,
141  gboolean selected);
142 gboolean bse_part_set_control_selected (BsePart *self,
143  guint id,
144  gboolean selected);
146  guint id;
147  BsePartEventType event_type;
148  guint channel;
149  guint tick;
150  gboolean selected;
151  /* note */
152  guint duration;
153  gint note;
154  gint fine_tune;
155  gfloat velocity;
156  /* note control */
157  gfloat fine_tune_value;
158  gfloat velocity_value;
159  /* control */
160  BseMidiSignalType control_type;
161  gfloat control_value;
162 };
163 
164 BsePartEventType bse_part_query_event (BsePart *self,
165  guint id,
166  BsePartQueryEvent *equery);
167 
168 
169 /* --- implementation details --- */
170 #define BSE_PART_MAX_CHANNELS (0x1024)
171 #define BSE_PART_MAX_TICK (0x7fffffff)
172 #define BSE_PART_INVAL_TICK_FLAG (0x80000000)
173 #define BSE_PART_NOTE_CONTROL(ctype) ((ctype) == BSE_MIDI_SIGNAL_VELOCITY || \
174  (ctype) == BSE_MIDI_SIGNAL_FINE_TUNE)
175 
176 /* --- BsePartControlChannel --- */
177 struct BsePartEventControl;
179  guint tick;
180  BsePartEventControl *events;
181 };
183  BsePartEventControl *next;
184  guint id : 31;
185  guint selected : 1;
186  guint ctype; /* BseMidiSignalType */
187  gfloat value; /* -1 .. 1 */
188 };
189 
190 void bse_part_controls_init (BsePartControls *self);
191 BsePartTickNode* bse_part_controls_lookup (BsePartControls *self,
192  guint tick);
193 BsePartEventControl* bse_part_controls_lookup_event (BsePartControls *self,
194  guint tick,
195  guint id);
196 BsePartTickNode* bse_part_controls_lookup_ge (BsePartControls *self,
197  guint tick);
198 BsePartTickNode* bse_part_controls_lookup_lt (BsePartControls *self,
199  guint tick);
200 BsePartTickNode* bse_part_controls_lookup_le (BsePartControls *self,
201  guint tick);
202 BsePartTickNode* bse_part_controls_get_bound (BsePartControls *self);
203 guint bse_part_controls_get_last_tick (BsePartControls *self);
204 BsePartTickNode* bse_part_controls_ensure_tick (BsePartControls *self,
205  guint tick);
206 void bse_part_controls_insert (BsePartControls *self,
207  BsePartTickNode *node,
208  guint id,
209  guint selected,
210  guint ctype,
211  gfloat value);
212 void bse_part_controls_change (BsePartControls *self,
213  BsePartTickNode *node,
214  BsePartEventControl *cev,
215  guint id,
216  guint selected,
217  guint ctype,
218  gfloat value);
219 void bse_part_controls_change_selected (BsePartEventControl *cev,
220  guint selected);
221 void bse_part_controls_remove (BsePartControls *self,
222  guint tick,
223  BsePartEventControl *cev);
224 void bse_part_controls_destroy (BsePartControls *self);
225 
227  guint tick;
228  guint id : 31;
229  guint selected : 1;
230  guint *crossings;
231  guint duration; /* in ticks */
232  gint note;
233  gint fine_tune;
234  gfloat velocity; /* 0 .. 1 */
235 };
236 
237 #define BSE_PART_NOTE_N_CROSSINGS(note) ((note)->crossings ? (note)->crossings[0] : 0)
238 #define BSE_PART_NOTE_CROSSING(note,j) ((note)->crossings[1 + (j)])
239 #define BSE_PART_SEMITONE_FACTOR(part,noteval) (bse_part_transpose_factor ((part), CLAMP ((noteval), SFI_MIN_NOTE, SFI_MAX_NOTE) - SFI_KAMMER_NOTE))
240 #define BSE_PART_NOTE_FREQ(part,note) (BSE_KAMMER_FREQUENCY * \
241  BSE_PART_SEMITONE_FACTOR ((part), (note)->note) * \
242  bse_cent_tune_fast ((note)->fine_tune))
243 
244 void bse_part_note_channel_init (BsePartNoteChannel *self);
245 BsePartEventNote* bse_part_note_channel_lookup (BsePartNoteChannel *self,
246  guint tick);
247 BsePartEventNote* bse_part_note_channel_lookup_le (BsePartNoteChannel *self,
248  guint tick);
249 BsePartEventNote* bse_part_note_channel_lookup_lt (BsePartNoteChannel *self,
250  guint tick);
251 BsePartEventNote* bse_part_note_channel_lookup_ge (BsePartNoteChannel *self,
252  guint tick);
253 BsePartEventNote* bse_part_note_channel_get_bound (BsePartNoteChannel *self);
254 guint bse_part_note_channel_get_last_tick (BsePartNoteChannel *self);
255 BsePartEventNote* bse_part_note_channel_insert (BsePartNoteChannel *self,
256  BsePartEventNote key);
257 void bse_part_note_channel_change_note (BsePartNoteChannel *self,
258  BsePartEventNote *note,
259  guint id,
260  gboolean selected,
261  gint vnote,
262  gint fine_tune,
263  gfloat velocity);
264 void bse_part_note_channel_remove (BsePartNoteChannel *self,
265  guint tick);
266 void bse_part_note_channel_destroy (BsePartNoteChannel *self);
267 
268 G_END_DECLS
269 
270 #endif /* __BSE_PART_H__ */
Definition: bsepart.hh:23
Definition: bsepart.hh:182
Definition: bsepart.hh:145
Definition: bsepart.hh:226
Definition: gbsearcharray.hh:37
Definition: bsepart.hh:47
Definition: bsepart.hh:20
Definition: bseitem.hh:39
Definition: bsepart.hh:178
Definition: bsepart.hh:26
Definition: bseitem.hh:33