BEAST/BSE - Better Audio System and Sound Engine  0.8.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
bsepattern.hh
Go to the documentation of this file.
00001  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __BSE_PATTERN_H__
00003 #define __BSE_PATTERN_H__
00004 
00005 #include        <bse/bseitem.hh>
00006 #include        <bse/bseeffect.h>
00007 
00008 
00009 #ifdef __cplusplus
00010 extern "C" {
00011 #endif /* __cplusplus */
00012 
00013 
00014 /* --- object type macros --- */
00015 #define BSE_TYPE_PATTERN              (BSE_TYPE_ID (BsePattern))
00016 #define BSE_PATTERN(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), BSE_TYPE_PATTERN, BsePattern))
00017 #define BSE_PATTERN_CLASS(class)      (G_TYPE_CHECK_CLASS_CAST ((class), BSE_TYPE_PATTERN, BsePatternClass))
00018 #define BSE_IS_PATTERN(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), BSE_TYPE_PATTERN))
00019 #define BSE_IS_PATTERN_CLASS(class)   (G_TYPE_CHECK_CLASS_TYPE ((class), BSE_TYPE_PATTERN))
00020 #define BSE_PATTERN_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), BSE_TYPE_PATTERN, BsePatternClass))
00021 
00022 
00023 /* --- accessors --- */
00024 #define BSE_PATTERN_N_CHANNELS(pattern) (((BsePattern*) (pattern))->n_channels)
00025 #define BSE_PATTERN_N_ROWS(pattern)     (((BsePattern*) (pattern))->n_rows)
00026 
00027 
00028 /* --- BsePattern object --- */
00029 struct _BsePatternNote
00030 {
00031   BseInstrument *instrument;
00032   guint          note : 20;
00033   guint          n_effects : 8;
00034   guint          selected : 1;
00035   BseEffect    **effects;
00036 };
00037 struct _BsePattern
00038 {
00039   BseItem parent_object;
00040 
00041   guint   n_channels            /* mirrored from BseSong */;
00042   guint   n_rows                /* mirrored from BseSong.pattern_length */;
00043 
00044   BsePatternNote *notes         /* ->notes [ row * n_channels + channel] */;
00045 
00046   /* only used during parsing phase */
00047   guint   current_channel;
00048   guint   current_row;
00049 };
00050 struct _BsePatternClass
00051 {
00052   BseItemClass parent_class;
00053 };
00054 
00055 
00056 /* --- prototypes --- */
00057 /* returns a pointer to relocatable data, make sure to lock the
00058  * pattern to maintain validity.
00059  */
00060 BsePatternNote* bse_pattern_peek_note           (BsePattern     *pattern,
00061                                                  guint           channel,
00062                                                  guint           row);
00063 GList* /*fl*/   bse_pattern_list_selection      (BsePattern     *pattern);
00064 gboolean        bse_pattern_has_selection       (BsePattern     *pattern);
00065 void            bse_pattern_modify_note         (BsePattern     *pattern,
00066                                                  guint           channel,
00067                                                  guint           row,
00068                                                  gint            note,
00069                                                  BseInstrument  *instrument);
00070 guint           bse_pattern_note_get_n_effects  (BsePattern     *pattern,
00071                                                  guint           channel,
00072                                                  guint           row);
00073 BseEffect*      bse_pattern_note_get_effect     (BsePattern     *pattern,
00074                                                  guint           channel,
00075                                                  guint           row,
00076                                                  guint           index);
00077 BseEffect*      bse_pattern_note_find_effect    (BsePattern     *pattern,
00078                                                  guint           channel,
00079                                                  guint           row,
00080                                                  GType           effect_type);
00081 void            bse_pattern_note_actuate_effect (BsePattern     *pattern,
00082                                                  guint           channel,
00083                                                  guint           row,
00084                                                  GType           effect_type);
00085 void            bse_pattern_note_drop_effect    (BsePattern     *pattern,
00086                                                  guint           channel,
00087                                                  guint           row,
00088                                                  GType           effect_type);
00089 
00090 
00091 /* --- convenience --- */
00092 void            bse_pattern_set_note        (BsePattern         *pattern,
00093                                              guint               channel,
00094                                              guint               row,
00095                                              gint                note);
00096 void            bse_pattern_set_instrument  (BsePattern         *pattern,
00097                                              guint               channel,
00098                                              guint               row,
00099                                              BseInstrument      *instrument);
00100 
00101 
00102 /* --- internal --- */
00103 void            bse_pattern_set_n_channels  (BsePattern         *pattern,
00104                                              guint               n_channels);
00105 void            bse_pattern_set_n_rows      (BsePattern         *pattern,
00106                                              guint               n_rows);
00107 void            bse_pattern_select_note     (BsePattern         *pattern,
00108                                              guint               channel,
00109                                              guint               row);
00110 void            bse_pattern_unselect_note   (BsePattern         *pattern,
00111                                              guint               channel,
00112                                              guint               row);
00113 
00114 
00115 /* --- selections --- */
00116 /* selections within a BsePattern are supplied for procedure invocation
00117  * from a pattern editor only, they don't actually affect core BSE
00118  * behaviour. thus we provide functions to keep an external selection
00119  * mask updated and functions to sync that with a pattern's inetrnal
00120  * selection.
00121  */
00122 void     bse_pattern_save_selection       (BsePattern  *pattern,
00123                                            guint32     *selection);
00124 void     bse_pattern_restore_selection    (BsePattern  *pattern,
00125                                            guint32     *selection);
00126 guint32* bse_pattern_selection_new        (guint        n_channels,
00127                                            guint        n_rows);
00128 guint32* bse_pattern_selection_copy       (guint32     *src_selection);
00129 void     bse_pattern_selection_free       (guint32     *selection);
00130 void     bse_pattern_selection_fill       (guint32     *selection,
00131                                            gboolean     selected);
00132 #define  BSE_PATTERN_SELECTION_N_CHANNELS(selection)  (selection[0])
00133 #define  BSE_PATTERN_SELECTION_N_ROWS(selection)      (selection[1])
00134 #define  BSE_PATTERN_SELECTION_MARK(selection, channel, row)    \
00135   _bse_pattern_selection_mark ((selection), (channel), (row))
00136 #define  BSE_PATTERN_SELECTION_UNMARK(selection, channel, row)  \
00137   _bse_pattern_selection_unmark ((selection), (channel), (row))
00138 #define  BSE_PATTERN_SELECTION_TEST(selection, channel, row)    \
00139   _bse_pattern_selection_test ((selection), (channel), (row))
00140 
00141 
00142 /* --- implementation details --- */
00143 static inline gboolean
00144 _bse_pattern_selection_test (guint32 *selection,
00145                              guint    channel,
00146                              guint    row)
00147 {
00148   guint n = BSE_PATTERN_SELECTION_N_CHANNELS (selection) * row + channel;
00149 
00150   /* return (selection[n / 32 + 2] & (1 << n % 32)) != 0; */
00151   return (selection[(n >> 5) + 2] & (1 << (n & 0x1f))) != 0;
00152 }
00153 static inline void
00154 _bse_pattern_selection_mark (guint32 *selection,
00155                              guint    channel,
00156                              guint    row)
00157 {
00158   guint n = BSE_PATTERN_SELECTION_N_CHANNELS (selection) * row + channel;
00159 
00160   selection[(n >> 5) + 2] |= 1 << (n & 0x1f);
00161 }
00162 static inline void
00163 _bse_pattern_selection_unmark (guint32 *selection,
00164                                guint    channel,
00165                                guint    row)
00166 {
00167   guint n = BSE_PATTERN_SELECTION_N_CHANNELS (selection) * row + channel;
00168 
00169   selection[(n >> 5) + 2] &= ~(1 << (n & 0x1f));
00170 }
00171 
00172 
00173 #ifdef __cplusplus
00174 }
00175 #endif /* __cplusplus */
00176 
00177 #endif /* __BSE_PATTERN_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines