BEAST/BSE - Better Audio System and Sound Engine  0.8.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
bsepart.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_PART_H__
00003 #define __BSE_PART_H__
00004 
00005 #include <bse/bseitem.hh>
00006 #include <sfi/gbsearcharray.hh>
00007 
00008 G_BEGIN_DECLS
00009 
00010 /* --- object type macros --- */
00011 #define BSE_TYPE_PART                   (BSE_TYPE_ID (BsePart))
00012 #define BSE_PART(object)                (G_TYPE_CHECK_INSTANCE_CAST ((object), BSE_TYPE_PART, BsePart))
00013 #define BSE_PART_CLASS(class)           (G_TYPE_CHECK_CLASS_CAST ((class), BSE_TYPE_PART, BsePartClass))
00014 #define BSE_IS_PART(object)             (G_TYPE_CHECK_INSTANCE_TYPE ((object), BSE_TYPE_PART))
00015 #define BSE_IS_PART_CLASS(class)        (G_TYPE_CHECK_CLASS_TYPE ((class), BSE_TYPE_PART))
00016 #define BSE_PART_GET_CLASS(object)      (G_TYPE_INSTANCE_GET_CLASS ((object), BSE_TYPE_PART, BsePartClass))
00017 
00018 
00019 /* --- typedefs & structures --- */
00020 struct BsePartControls {
00021   GBSearchArray *bsa;
00022 };
00023 struct BsePartNoteChannel {
00024   GBSearchArray *bsa;
00025 };
00026 struct BsePart : BseItem {
00027   const double       *semitone_table; // [-132..+132] only updated when not playing
00028   /* id -> tick lookups */
00029   guint               n_ids;
00030   guint              *ids;
00031   guint               last_id;        /* head of free id list */
00032   /* control events */
00033   BsePartControls     controls;
00034   /* notes */
00035   guint               n_channels;
00036   BsePartNoteChannel *channels;
00037   /* one after any tick used by controls or notes */
00038   guint               last_tick_SL;
00039   /* queued updates */
00040   guint               links_queued : 1;
00041   guint               range_queued : 1;
00042   guint               range_tick;
00043   guint               range_bound;
00044   gint                range_min_note;
00045   gint                range_max_note;
00046 };
00047 struct BsePartClass : BseItemClass {
00048   void  (*range_changed)        (BsePart        *part,
00049                                  guint           tick,
00050                                  guint           duration,
00051                                  gint            range_min_note,
00052                                  gint            range_max_note);
00053 };
00054 typedef enum    /*< skip >*/
00055 {
00056   BSE_PART_EVENT_NONE,
00057   BSE_PART_EVENT_CONTROL,
00058   BSE_PART_EVENT_NOTE
00059 } BsePartEventType;
00060 
00061 #define            bse_part_transpose_factor(          part, index /* -132..+132*/)     ((part)->semitone_table[index])
00062 void               bse_part_set_semitone_table        (BsePart           *self,
00063                                                        const double      *semitone_table);
00064 void               bse_part_links_changed             (BsePart           *self);
00065 BsePartLinkSeq*    bse_part_list_links                (BsePart           *self);
00066 gboolean           bse_part_delete_control            (BsePart           *self,
00067                                                        guint              id);
00068 gboolean           bse_part_delete_note               (BsePart           *self,
00069                                                        guint              id,
00070                                                        guint              channel);
00071 guint              bse_part_insert_note               (BsePart           *self,
00072                                                        guint              channel,
00073                                                        guint              tick,
00074                                                        guint              duration,
00075                                                        gint               note,
00076                                                        gint               fine_tune,
00077                                                        gfloat             velocity);
00078 guint              bse_part_insert_control            (BsePart           *self,
00079                                                        guint              tick,
00080                                                        BseMidiSignalType  ctype,
00081                                                        gfloat             value);
00082 gboolean           bse_part_change_note               (BsePart           *self,
00083                                                        guint              id,
00084                                                        guint              channel,
00085                                                        guint              tick,
00086                                                        guint              duration,
00087                                                        gint               note,
00088                                                        gint               fine_tune,
00089                                                        gfloat             velocity);
00090 gboolean           bse_part_change_control            (BsePart           *self,
00091                                                        guint              id,
00092                                                        guint              tick,
00093                                                        BseMidiSignalType  ctype,
00094                                                        gfloat             value);
00095 BsePartNoteSeq*    bse_part_list_notes                (BsePart           *self,
00096                                                        guint              channel,
00097                                                        guint              tick,
00098                                                        guint              duration,
00099                                                        gint               min_note,
00100                                                        gint               max_note,
00101                                                        gboolean           include_crossings);
00102 BsePartControlSeq* bse_part_list_controls             (BsePart           *self,
00103                                                        guint              channel, /* for note events */
00104                                                        guint              tick,
00105                                                        guint              duration,
00106                                                        BseMidiSignalType  ctype);
00107 void               bse_part_queue_notes_within        (BsePart           *self,
00108                                                        guint              tick,
00109                                                        guint              duration,
00110                                                        gint               min_note,
00111                                                        gint               max_note);
00112 #define            bse_part_queue_controls(p,t,d)          bse_part_queue_notes_within (p, t, d, BSE_MIN_NOTE, BSE_MAX_NOTE)
00113 BsePartNoteSeq*    bse_part_list_selected_notes       (BsePart           *self);
00114 BsePartControlSeq* bse_part_list_selected_controls    (BsePart           *self,
00115                                                        BseMidiSignalType  ctype);
00116 void               bse_part_select_notes              (BsePart           *self,
00117                                                        guint              channel,
00118                                                        guint              tick,
00119                                                        guint              duration,
00120                                                        gint               min_note,
00121                                                        gint               max_note,
00122                                                        gboolean           selected);
00123 void               bse_part_select_controls           (BsePart           *self,
00124                                                        guint              tick,
00125                                                        guint              duration,
00126                                                        BseMidiSignalType  ctype,
00127                                                        gboolean           selected);
00128 void               bse_part_select_notes_exclusive    (BsePart           *self,
00129                                                        guint              channel,
00130                                                        guint              tick,
00131                                                        guint              duration,
00132                                                        gint               min_note,
00133                                                        gint               max_note);
00134 void               bse_part_select_controls_exclusive (BsePart           *self,
00135                                                        guint              tick,
00136                                                        guint              duration,
00137                                                        BseMidiSignalType  ctype);
00138 gboolean           bse_part_set_note_selected         (BsePart           *self,
00139                                                        guint              id,
00140                                                        guint              channel,
00141                                                        gboolean           selected);
00142 gboolean           bse_part_set_control_selected      (BsePart           *self,
00143                                                        guint              id,
00144                                                        gboolean           selected);
00145 struct BsePartQueryEvent {
00146   guint             id;
00147   BsePartEventType  event_type;
00148   guint             channel;
00149   guint             tick;
00150   gboolean          selected;
00151   /* note */
00152   guint             duration;
00153   gint              note;
00154   gint              fine_tune;
00155   gfloat            velocity;
00156   /* note control */
00157   gfloat            fine_tune_value;
00158   gfloat            velocity_value;
00159   /* control */
00160   BseMidiSignalType control_type;
00161   gfloat            control_value;
00162 };
00163 
00164 BsePartEventType   bse_part_query_event         (BsePart           *self,
00165                                                  guint              id,
00166                                                  BsePartQueryEvent *equery);
00167 
00168 
00169 /* --- implementation details --- */
00170 #define BSE_PART_MAX_CHANNELS           (0x1024)
00171 #define BSE_PART_MAX_TICK               (0x7fffffff)
00172 #define BSE_PART_INVAL_TICK_FLAG        (0x80000000)
00173 #define BSE_PART_NOTE_CONTROL(ctype)    ((ctype) == BSE_MIDI_SIGNAL_VELOCITY || \
00174                                          (ctype) == BSE_MIDI_SIGNAL_FINE_TUNE)
00175 
00176 /* --- BsePartControlChannel --- */
00177 struct BsePartEventControl;
00178 struct BsePartTickNode {
00179   guint                tick;
00180   BsePartEventControl *events;
00181 };
00182 struct BsePartEventControl {
00183   BsePartEventControl   *next;
00184   guint                  id : 31;
00185   guint                  selected : 1;
00186   guint                  ctype; /* BseMidiSignalType */
00187   gfloat                 value;         /* -1 .. 1 */
00188 };
00189 
00190 void                 bse_part_controls_init            (BsePartControls     *self);
00191 BsePartTickNode*     bse_part_controls_lookup          (BsePartControls     *self,
00192                                                         guint                tick);
00193 BsePartEventControl* bse_part_controls_lookup_event    (BsePartControls     *self,
00194                                                         guint                tick,
00195                                                         guint                id);
00196 BsePartTickNode*     bse_part_controls_lookup_ge       (BsePartControls     *self,
00197                                                         guint                tick);
00198 BsePartTickNode*     bse_part_controls_lookup_lt       (BsePartControls     *self,
00199                                                         guint                tick);
00200 BsePartTickNode*     bse_part_controls_lookup_le       (BsePartControls     *self,
00201                                                         guint                tick);
00202 BsePartTickNode*     bse_part_controls_get_bound       (BsePartControls     *self);
00203 guint                bse_part_controls_get_last_tick   (BsePartControls     *self);
00204 BsePartTickNode*     bse_part_controls_ensure_tick     (BsePartControls     *self,
00205                                                         guint                tick);
00206 void                 bse_part_controls_insert          (BsePartControls     *self,
00207                                                         BsePartTickNode     *node,
00208                                                         guint                id,
00209                                                         guint                selected,
00210                                                         guint                ctype,
00211                                                         gfloat               value);
00212 void                 bse_part_controls_change          (BsePartControls     *self,
00213                                                         BsePartTickNode     *node,
00214                                                         BsePartEventControl *cev,
00215                                                         guint                id,
00216                                                         guint                selected,
00217                                                         guint                ctype,
00218                                                         gfloat               value);
00219 void                 bse_part_controls_change_selected (BsePartEventControl *cev,
00220                                                         guint                selected);
00221 void                 bse_part_controls_remove          (BsePartControls     *self,
00222                                                         guint                tick,
00223                                                         BsePartEventControl *cev);
00224 void                 bse_part_controls_destroy         (BsePartControls     *self);
00225 
00226 struct BsePartEventNote {
00227   guint                  tick;
00228   guint                  id : 31;
00229   guint                  selected : 1;
00230   guint                 *crossings;
00231   guint                  duration;      /* in ticks */
00232   gint                   note;
00233   gint                   fine_tune;
00234   gfloat                 velocity;      /* 0 .. 1 */
00235 };
00236 
00237 #define BSE_PART_NOTE_N_CROSSINGS(note)         ((note)->crossings ? (note)->crossings[0] : 0)
00238 #define BSE_PART_NOTE_CROSSING(note,j)          ((note)->crossings[1 + (j)])
00239 #define BSE_PART_SEMITONE_FACTOR(part,noteval)  (bse_part_transpose_factor ((part), CLAMP ((noteval), SFI_MIN_NOTE, SFI_MAX_NOTE) - SFI_KAMMER_NOTE))
00240 #define BSE_PART_NOTE_FREQ(part,note)           (BSE_KAMMER_FREQUENCY *                                 \
00241                                                  BSE_PART_SEMITONE_FACTOR ((part), (note)->note) *      \
00242                                                  bse_cent_tune_fast ((note)->fine_tune))
00243 
00244 void              bse_part_note_channel_init          (BsePartNoteChannel *self);
00245 BsePartEventNote* bse_part_note_channel_lookup        (BsePartNoteChannel *self,
00246                                                        guint               tick);
00247 BsePartEventNote* bse_part_note_channel_lookup_le     (BsePartNoteChannel *self,
00248                                                        guint               tick);
00249 BsePartEventNote* bse_part_note_channel_lookup_lt     (BsePartNoteChannel *self,
00250                                                        guint               tick);
00251 BsePartEventNote* bse_part_note_channel_lookup_ge     (BsePartNoteChannel *self,
00252                                                        guint               tick);
00253 BsePartEventNote* bse_part_note_channel_get_bound     (BsePartNoteChannel *self);
00254 guint             bse_part_note_channel_get_last_tick (BsePartNoteChannel *self);
00255 BsePartEventNote* bse_part_note_channel_insert        (BsePartNoteChannel *self,
00256                                                        BsePartEventNote    key);
00257 void              bse_part_note_channel_change_note   (BsePartNoteChannel *self,
00258                                                        BsePartEventNote   *note,
00259                                                        guint               id,
00260                                                        gboolean            selected,
00261                                                        gint                vnote,
00262                                                        gint                fine_tune,
00263                                                        gfloat              velocity);
00264 void              bse_part_note_channel_remove        (BsePartNoteChannel *self,
00265                                                        guint               tick);
00266 void              bse_part_note_channel_destroy       (BsePartNoteChannel *self);
00267 
00268 G_END_DECLS
00269 
00270 #endif /* __BSE_PART_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines