2 Calf Box, an open source musical instrument.
3 Copyright (C) 2010-2011 Krzysztof Foltman
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 struct cbox_midi_pattern
;
31 /////////////////////////////////////////////////////////////////////////////////////////////////////
33 struct cbox_midi_playback_active_notes
35 uint16_t channels_active
;
36 uint32_t notes
[16][4]; // 0..127
39 extern void cbox_midi_playback_active_notes_init(struct cbox_midi_playback_active_notes
*notes
);
40 extern void cbox_midi_playback_active_notes_copy(struct cbox_midi_playback_active_notes
*dest
, const struct cbox_midi_playback_active_notes
*src
);
41 extern void cbox_midi_playback_active_notes_clear(struct cbox_midi_playback_active_notes
*notes
);
42 extern int cbox_midi_playback_active_notes_release(struct cbox_midi_playback_active_notes
*notes
, struct cbox_midi_buffer
*buf
);
44 /////////////////////////////////////////////////////////////////////////////////////////////////////
46 struct cbox_midi_pattern_playback
48 struct cbox_midi_event
*events
;
52 extern struct cbox_midi_pattern_playback
*cbox_midi_pattern_playback_new(struct cbox_midi_pattern
*pattern
);
53 extern void cbox_midi_pattern_playback_destroy(struct cbox_midi_pattern_playback
*mppb
);
55 /////////////////////////////////////////////////////////////////////////////////////////////////////
57 struct cbox_midi_clip_playback
59 struct cbox_midi_pattern_playback
*pattern
;
60 struct cbox_master
*master
;
64 // [start, end) of the pattern slice
65 int start_time_samples
, end_time_samples
;
66 int item_start_ppqn
, min_time_ppqn
;
68 struct cbox_midi_playback_active_notes
*active_notes
;
71 extern void cbox_midi_clip_playback_init(struct cbox_midi_clip_playback
*pb
, struct cbox_midi_playback_active_notes
*active_notes
, struct cbox_master
*master
);
72 extern void cbox_midi_clip_playback_render(struct cbox_midi_clip_playback
*pb
, struct cbox_midi_buffer
*buf
, int offset
, int nsamples
);
73 extern void cbox_midi_clip_playback_seek_ppqn(struct cbox_midi_clip_playback
*pb
, int time_ppqn
, int skip_this_pos
);
74 extern void cbox_midi_clip_playback_seek_samples(struct cbox_midi_clip_playback
*pb
, int time_samples
);
75 extern void cbox_midi_clip_playback_set_pattern(struct cbox_midi_clip_playback
*pb
, struct cbox_midi_pattern_playback
*pattern
, int start_time_samples
, int end_time_samples
, int item_start_ppqn
, int offset_ppqn
);
77 /////////////////////////////////////////////////////////////////////////////////////////////////////
79 // all times in this structure are in PPQN
80 struct cbox_track_playback_item
83 struct cbox_midi_pattern_playback
*pattern
;
86 // in future, it should also contain a pre-calculated list of notes to release
89 struct cbox_track_playback
91 struct cbox_track
*track
; // used as identification only
92 struct cbox_track_playback_item
*items
;
93 struct cbox_master
*master
;
96 struct cbox_midi_buffer output_buffer
;
97 struct cbox_midi_clip_playback playback
;
98 struct cbox_midi_playback_active_notes active_notes
;
99 struct cbox_midi_merger
*external_merger
;
100 struct cbox_song_playback
*spb
;
101 struct cbox_track_playback
*old_state
;
102 gboolean state_copied
;
105 extern struct cbox_track_playback
*cbox_track_playback_new_from_track(struct cbox_track
*track
, struct cbox_master
*master
, struct cbox_song_playback
*spb
, struct cbox_track_playback
*old_state
);
106 extern void cbox_track_playback_render(struct cbox_track_playback
*pb
, int offset
, int nsamples
);
107 extern void cbox_track_playback_seek_ppqn(struct cbox_track_playback
*pb
, int time_ppqn
, int min_time_ppqn
);
108 extern void cbox_track_playback_seek_samples(struct cbox_track_playback
*pb
, int time_samples
);
109 extern void cbox_track_playback_start_item(struct cbox_track_playback
*pb
, int time
, int is_ppqn
, int skip_this_pos
);
110 extern void cbox_track_playback_destroy(struct cbox_track_playback
*pb
);
112 /////////////////////////////////////////////////////////////////////////////////////////////////////
114 struct cbox_tempo_map_item
117 uint32_t time_samples
;
119 int timesig_nom
, timesig_denom
;
120 // should also have a bar/beat position to make things easier
123 /////////////////////////////////////////////////////////////////////////////////////////////////////
125 struct cbox_adhoc_pattern
127 struct cbox_adhoc_pattern
*next
;
129 struct cbox_midi_pattern
*pattern
;
130 struct cbox_midi_pattern_playback
*pattern_playback
;
132 struct cbox_midi_playback_active_notes active_notes
;
133 struct cbox_midi_clip_playback playback
;
135 struct cbox_midi_buffer output_buffer
;
140 extern struct cbox_adhoc_pattern
*cbox_adhoc_pattern_new(struct cbox_master
*master
, int id
, struct cbox_midi_pattern
*pattern
);
141 extern void cbox_adhoc_pattern_render(struct cbox_adhoc_pattern
*adp
, int offset
, int nsamples
);
142 extern void cbox_adhoc_pattern_destroy(struct cbox_adhoc_pattern
*ap
);
144 /////////////////////////////////////////////////////////////////////////////////////////////////////
146 struct cbox_song_playback
148 struct cbox_master
*master
;
149 struct cbox_song
*song
; // for identification only
150 struct cbox_track_playback
**tracks
;
152 struct cbox_tempo_map_item
*tempo_map_items
;
153 int tempo_map_item_count
;
155 uint32_t song_pos_samples
, song_pos_ppqn
, min_time_ppqn
;
156 uint32_t loop_start_ppqn
, loop_end_ppqn
;
157 GHashTable
*pattern_map
;
158 struct cbox_midi_merger track_merger
;
159 struct cbox_engine
*engine
;
161 struct cbox_adhoc_pattern
*adhoc_patterns
, *retired_adhoc_patterns
;
164 extern struct cbox_song_playback
*cbox_song_playback_new(struct cbox_song
*song
, struct cbox_master
*master
, struct cbox_engine
*engine
, struct cbox_song_playback
*old_state
);
165 extern void cbox_song_playback_render(struct cbox_song_playback
*spb
, struct cbox_midi_buffer
*output
, int nsamples
);
166 extern int cbox_song_playback_active_notes_release(struct cbox_song_playback
*spb
, struct cbox_midi_buffer
*buf
);
167 extern void cbox_song_playback_seek_ppqn(struct cbox_song_playback
*spb
, int time_ppqn
, int skip_this_pos
);
168 extern void cbox_song_playback_seek_samples(struct cbox_song_playback
*spb
, int time_samples
);
169 extern int cbox_song_playback_tmi_from_ppqn(struct cbox_song_playback
*spb
, int time_ppqn
);
170 extern int cbox_song_playback_tmi_from_samples(struct cbox_song_playback
*spb
, int time_samples
);
171 struct cbox_midi_pattern_playback
*cbox_song_playback_get_pattern(struct cbox_song_playback
*spb
, struct cbox_midi_pattern
*pattern
);
172 extern void cbox_song_playback_apply_old_state(struct cbox_song_playback
*spb
);
173 extern void cbox_song_playback_destroy(struct cbox_song_playback
*spb
);