BEAST/BSE - Better Audio System and Sound Engine  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bsepattern.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_PATTERN_H__
3 #define __BSE_PATTERN_H__
4 
5 #include <bse/bseitem.hh>
6 #include <bse/bseeffect.h>
7 
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif /* __cplusplus */
12 
13 
14 /* --- object type macros --- */
15 #define BSE_TYPE_PATTERN (BSE_TYPE_ID (BsePattern))
16 #define BSE_PATTERN(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), BSE_TYPE_PATTERN, BsePattern))
17 #define BSE_PATTERN_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), BSE_TYPE_PATTERN, BsePatternClass))
18 #define BSE_IS_PATTERN(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), BSE_TYPE_PATTERN))
19 #define BSE_IS_PATTERN_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), BSE_TYPE_PATTERN))
20 #define BSE_PATTERN_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), BSE_TYPE_PATTERN, BsePatternClass))
21 
22 
23 /* --- accessors --- */
24 #define BSE_PATTERN_N_CHANNELS(pattern) (((BsePattern*) (pattern))->n_channels)
25 #define BSE_PATTERN_N_ROWS(pattern) (((BsePattern*) (pattern))->n_rows)
26 
27 
28 /* --- BsePattern object --- */
30 {
31  BseInstrument *instrument;
32  guint note : 20;
33  guint n_effects : 8;
34  guint selected : 1;
35  BseEffect **effects;
36 };
38 {
39  BseItem parent_object;
40 
41  guint n_channels /* mirrored from BseSong */;
42  guint n_rows /* mirrored from BseSong.pattern_length */;
43 
44  BsePatternNote *notes /* ->notes [ row * n_channels + channel] */;
45 
46  /* only used during parsing phase */
47  guint current_channel;
48  guint current_row;
49 };
51 {
52  BseItemClass parent_class;
53 };
54 
55 
56 /* --- prototypes --- */
57 /* returns a pointer to relocatable data, make sure to lock the
58  * pattern to maintain validity.
59  */
60 BsePatternNote* bse_pattern_peek_note (BsePattern *pattern,
61  guint channel,
62  guint row);
63 GList* /*fl*/ bse_pattern_list_selection (BsePattern *pattern);
64 gboolean bse_pattern_has_selection (BsePattern *pattern);
65 void bse_pattern_modify_note (BsePattern *pattern,
66  guint channel,
67  guint row,
68  gint note,
69  BseInstrument *instrument);
70 guint bse_pattern_note_get_n_effects (BsePattern *pattern,
71  guint channel,
72  guint row);
73 BseEffect* bse_pattern_note_get_effect (BsePattern *pattern,
74  guint channel,
75  guint row,
76  guint index);
77 BseEffect* bse_pattern_note_find_effect (BsePattern *pattern,
78  guint channel,
79  guint row,
80  GType effect_type);
81 void bse_pattern_note_actuate_effect (BsePattern *pattern,
82  guint channel,
83  guint row,
84  GType effect_type);
85 void bse_pattern_note_drop_effect (BsePattern *pattern,
86  guint channel,
87  guint row,
88  GType effect_type);
89 
90 
91 /* --- convenience --- */
92 void bse_pattern_set_note (BsePattern *pattern,
93  guint channel,
94  guint row,
95  gint note);
96 void bse_pattern_set_instrument (BsePattern *pattern,
97  guint channel,
98  guint row,
99  BseInstrument *instrument);
100 
101 
102 /* --- internal --- */
103 void bse_pattern_set_n_channels (BsePattern *pattern,
104  guint n_channels);
105 void bse_pattern_set_n_rows (BsePattern *pattern,
106  guint n_rows);
107 void bse_pattern_select_note (BsePattern *pattern,
108  guint channel,
109  guint row);
110 void bse_pattern_unselect_note (BsePattern *pattern,
111  guint channel,
112  guint row);
113 
114 
115 /* --- selections --- */
116 /* selections within a BsePattern are supplied for procedure invocation
117  * from a pattern editor only, they don't actually affect core BSE
118  * behaviour. thus we provide functions to keep an external selection
119  * mask updated and functions to sync that with a pattern's inetrnal
120  * selection.
121  */
122 void bse_pattern_save_selection (BsePattern *pattern,
123  guint32 *selection);
124 void bse_pattern_restore_selection (BsePattern *pattern,
125  guint32 *selection);
126 guint32* bse_pattern_selection_new (guint n_channels,
127  guint n_rows);
128 guint32* bse_pattern_selection_copy (guint32 *src_selection);
129 void bse_pattern_selection_free (guint32 *selection);
130 void bse_pattern_selection_fill (guint32 *selection,
131  gboolean selected);
132 #define BSE_PATTERN_SELECTION_N_CHANNELS(selection) (selection[0])
133 #define BSE_PATTERN_SELECTION_N_ROWS(selection) (selection[1])
134 #define BSE_PATTERN_SELECTION_MARK(selection, channel, row) \
135  _bse_pattern_selection_mark ((selection), (channel), (row))
136 #define BSE_PATTERN_SELECTION_UNMARK(selection, channel, row) \
137  _bse_pattern_selection_unmark ((selection), (channel), (row))
138 #define BSE_PATTERN_SELECTION_TEST(selection, channel, row) \
139  _bse_pattern_selection_test ((selection), (channel), (row))
140 
141 
142 /* --- implementation details --- */
143 static inline gboolean
144 _bse_pattern_selection_test (guint32 *selection,
145  guint channel,
146  guint row)
147 {
148  guint n = BSE_PATTERN_SELECTION_N_CHANNELS (selection) * row + channel;
149 
150  /* return (selection[n / 32 + 2] & (1 << n % 32)) != 0; */
151  return (selection[(n >> 5) + 2] & (1 << (n & 0x1f))) != 0;
152 }
153 static inline void
154 _bse_pattern_selection_mark (guint32 *selection,
155  guint channel,
156  guint row)
157 {
158  guint n = BSE_PATTERN_SELECTION_N_CHANNELS (selection) * row + channel;
159 
160  selection[(n >> 5) + 2] |= 1 << (n & 0x1f);
161 }
162 static inline void
163 _bse_pattern_selection_unmark (guint32 *selection,
164  guint channel,
165  guint row)
166 {
167  guint n = BSE_PATTERN_SELECTION_N_CHANNELS (selection) * row + channel;
168 
169  selection[(n >> 5) + 2] &= ~(1 << (n & 0x1f));
170 }
171 
172 
173 #ifdef __cplusplus
174 }
175 #endif /* __cplusplus */
176 
177 #endif /* __BSE_PATTERN_H__ */
Definition: bsepattern.hh:29
Definition: bsepattern.hh:37
Definition: bsepattern.hh:50
Definition: bseitem.hh:39
Definition: bseitem.hh:33