Ardour  9.0-pre0-582-g084a23a80d
smf.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2007, 2008 Edward Tomasz NapieraƂa <trasz@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * ALTHOUGH THIS SOFTWARE IS MADE OF WIN AND SCIENCE, IT IS PROVIDED BY THE
15  * AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18  * THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
20  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
21  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 
216 #ifndef SMF_H
217 #define SMF_H
218 
219 #ifdef __cplusplus
220 extern "C" {
221 #endif
222 
223 #include <stdio.h>
224 #include <stdint.h>
225 #include <glib.h>
226 
227 #if defined(__GNUC__) && __GNUC__ >= 4
228 #define WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
229 #else
230 #define WARN_UNUSED_RESULT
231 #endif
232 
234 struct smf_struct {
235  int format;
236 
239  uint16_t ppqn;
243 
246  void *file_buffer;
250 
252  GPtrArray *tracks_array;
255 
258  GPtrArray *tempo_array;
259 };
260 
261 typedef struct smf_struct smf_t;
262 
265  size_t time_pulses;
271 };
272 
273 typedef struct smf_tempo_struct smf_tempo_t;
274 
278 
281  /* this will be set from the SMF file if present, during loading */
282  char* name;
283  char* instrument;
285  void *file_buffer;
287  int last_status; /* Used for "running status". */
288 
293 
296  GPtrArray *events_array;
297 };
298 
299 typedef struct smf_track_struct smf_track_t;
300 
305 
307  size_t event_number;
308 
312 
314  size_t time_pulses;
315 
318 
320  uint8_t *midi_buffer;
321 
324 };
325 
326 typedef struct smf_event_struct smf_event_t;
327 
328 /* Routines for manipulating smf_t. */
330 void smf_delete(smf_t *smf);
331 
333 int smf_set_ppqn(smf_t *smf, uint16_t ppqn) WARN_UNUSED_RESULT;
334 
336 
338 
342 
343 void smf_rewind(smf_t *smf);
344 int smf_seek_to_pulses(smf_t *smf, size_t pulses) WARN_UNUSED_RESULT;
346 
349 
352 
353 /* Routines for manipulating smf_track_t. */
356 
360 
366 
367 /* Routines for manipulating smf_event_t. */
369 smf_event_t *smf_event_new_from_pointer(const void *midi_data, size_t len) WARN_UNUSED_RESULT;
370 smf_event_t *smf_event_new_from_bytes(int byte1, int byte2, int byte3) WARN_UNUSED_RESULT;
373 
383 
384 /* Routines for dealing with Variable Length Quantities (VLQ's).
385  Slightly odd names reflect original static names within libsmf
386  */
387 int smf_format_vlq (unsigned char *buf, int length, unsigned long value);
388 int smf_extract_vlq(const unsigned char *buf, const size_t buffer_length, uint32_t *value, uint32_t *len);
389 
390 /* Routines for loading SMF files. */
392 smf_t *smf_load_from_memory(void *buffer, const size_t buffer_length) WARN_UNUSED_RESULT;
393 
394 /* Routine for writing SMF files. */
396 
397 /* Routines for manipulating smf_tempo_t. */
403 
405 
406 #ifdef __cplusplus
407 }
408 #endif
409 
410 #endif /* SMF_H */
411 
PBD::PropertyDescriptor< timecnt_t > length
GTKMM_API const Gtk::BuiltinStockID FILE
int smf_event_is_textual(const smf_event_t *event)
void smf_event_remove_from_track(smf_event_t *event)
int smf_event_is_system_realtime(const smf_event_t *event)
void smf_track_add_event_delta_pulses(smf_track_t *track, smf_event_t *event, uint32_t delta)
int smf_track_add_eot_pulses(smf_track_t *track, size_t pulses)
char * smf_decode(const smf_t *smf)
size_t smf_get_length_pulses(const smf_t *smf)
void smf_delete(smf_t *smf)
smf_event_t * smf_track_get_event_by_number(const smf_track_t *track, size_t num)
char * smf_event_extract_text(const smf_event_t *event)
int smf_extract_vlq(const unsigned char *buf, const size_t buffer_length, uint32_t *value, uint32_t *len)
int smf_event_is_sysex(const smf_event_t *event)
int smf_event_is_last(const smf_event_t *event)
void smf_track_add_event_pulses(smf_track_t *track, smf_event_t *event, size_t pulses)
smf_event_t * smf_track_get_last_event(const smf_track_t *track)
int smf_format_vlq(unsigned char *buf, int length, unsigned long value)
int smf_event_is_valid(const smf_event_t *event)
smf_t * smf_load_from_memory(void *buffer, const size_t buffer_length)
#define WARN_UNUSED_RESULT
Definition: smf.h:230
void smf_add_track(smf_t *smf, smf_track_t *track)
smf_event_t * smf_event_new_textual(int type, const char *text)
void smf_track_delete(smf_track_t *track)
smf_track_t * smf_track_new(void)
int smf_set_format(smf_t *smf, int format)
smf_event_t * smf_track_get_next_event(smf_track_t *track)
smf_event_t * smf_event_new_from_pointer(const void *midi_data, size_t len)
smf_track_t * smf_get_track_by_number(const smf_t *smf, int track_number)
void smf_skip_next_event(smf_t *smf)
void smf_rewind(smf_t *smf)
smf_event_t * smf_event_new_from_bytes(int byte1, int byte2, int byte3)
smf_t * smf_new(void)
int smf_event_is_metadata(const smf_event_t *event)
const char * smf_get_version(void)
int smf_track_add_eot_delta_pulses(smf_track_t *track, uint32_t delta)
smf_tempo_t * smf_get_tempo_by_seconds(const smf_t *smf, double seconds)
void smf_event_delete(smf_event_t *event)
void smf_track_remove_from_smf(smf_track_t *track)
smf_event_t * smf_peek_next_event(smf_t *smf)
int smf_set_ppqn(smf_t *smf, uint16_t ppqn)
int smf_event_is_system_common(const smf_event_t *event)
smf_tempo_t * smf_get_tempo_by_pulses(const smf_t *smf, size_t pulses)
smf_event_t * smf_event_new(void)
smf_tempo_t * smf_get_tempo_by_number(const smf_t *smf, size_t number)
int smf_save(smf_t *smf, FILE *file)
smf_t * smf_load(FILE *)
int smf_seek_to_pulses(smf_t *smf, size_t pulses)
int smf_get_tempo_count(const smf_t *smf)
int smf_event_is_eot(const smf_event_t *event)
char * smf_event_decode(const smf_event_t *event)
int smf_seek_to_event(smf_t *smf, const smf_event_t *event)
smf_tempo_t * smf_get_last_tempo(const smf_t *smf)
smf_event_t * smf_get_next_event(smf_t *smf)
int32_t delta_time_pulses
Definition: smf.h:311
int track_number
Definition: smf.h:317
size_t midi_buffer_length
Definition: smf.h:323
uint8_t * midi_buffer
Definition: smf.h:320
smf_track_t * track
Definition: smf.h:304
size_t event_number
Definition: smf.h:307
size_t time_pulses
Definition: smf.h:314
void * file_buffer
Definition: smf.h:246
GPtrArray * tracks_array
Definition: smf.h:252
size_t file_buffer_length
Definition: smf.h:247
FILE * stream
Definition: smf.h:245
int need_tempo_map_compute
Definition: smf.h:254
uint16_t ppqn
Definition: smf.h:239
int resolution
Definition: smf.h:241
int format
Definition: smf.h:235
size_t next_chunk_offset
Definition: smf.h:248
GPtrArray * tempo_array
Definition: smf.h:258
int frames_per_second
Definition: smf.h:240
double last_seek_position
Definition: smf.h:253
int number_of_tracks
Definition: smf.h:242
int expected_number_of_tracks
Definition: smf.h:249
int clocks_per_click
Definition: smf.h:269
size_t time_pulses
Definition: smf.h:265
int denominator
Definition: smf.h:268
int microseconds_per_quarter_note
Definition: smf.h:266
int notes_per_note
Definition: smf.h:270
int numerator
Definition: smf.h:267
int track_number
Definition: smf.h:279
size_t next_event_number
Definition: smf.h:292
size_t number_of_events
Definition: smf.h:280
size_t next_event_offset
Definition: smf.h:291
int last_status
Definition: smf.h:287
smf_t * smf
Definition: smf.h:277
void * file_buffer
Definition: smf.h:285
size_t time_of_next_event
Definition: smf.h:295
GPtrArray * events_array
Definition: smf.h:296
char * name
Definition: smf.h:282
size_t file_buffer_length
Definition: smf.h:286
char * instrument
Definition: smf.h:283