#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <errno.h>
#include <arpa/inet.h>
#include "smf.h"
#include "smf_private.h"
Go to the source code of this file.
|
static void * | smf_extend (smf_t *smf, const int length) |
|
static int | smf_append (smf_t *smf, const void *buffer, const int buffer_length) |
|
static int | write_mthd_header (smf_t *smf) |
|
static void * | track_extend (smf_track_t *track, const int length) |
|
static int | track_append (smf_track_t *track, const void *buffer, const int buffer_length) |
|
int | smf_format_vlq (unsigned char *buf, int length, unsigned long value) |
|
smf_event_t * | smf_event_new_textual (int type, const char *text) |
|
static int | write_vlq (smf_event_t *event, unsigned long value) |
|
static int | write_event_time (smf_event_t *event) |
|
static int | write_sysex_contents (smf_event_t *event) |
|
static int | write_escaped_event_contents (smf_event_t *event) |
|
static int | write_event_contents (smf_event_t *event) |
|
static int | write_event (smf_event_t *event) |
|
static int | write_mtrk_header (smf_track_t *track) |
|
static int | write_mtrk_length (smf_track_t *track) |
|
static int | write_track (smf_track_t *track) |
|
static int | write_file (smf_t *smf, FILE *stream) |
|
static void | free_buffer (smf_t *smf) |
|
static int | pointers_are_clear (smf_t *smf) |
|
int | smf_event_is_eot (const smf_event_t *event) |
|
static int | smf_validate (smf_t *smf) |
|
static int | check_smf_event_is_identical (const smf_event_t *a, const smf_event_t *b) |
|
static int | check_smf_track_is_identical (const smf_track_t *a, const smf_track_t *b) |
|
static int | check_smf_is_identical (const smf_t *a, const smf_t *b) |
|
static int | check_smf_saved_correctly (const smf_t *smf, FILE *file) |
|
int | smf_save (smf_t *smf, FILE *file) |
|
Standard MIDI File writer.
Definition in file smf_save.c.
#define CHECK |
( |
|
cond | ) |
if (!(cond)) { return -1; } |
#define MAX_VLQ_LENGTH 128 |
static int check_smf_is_identical |
( |
const smf_t * |
a, |
|
|
const smf_t * |
b |
|
) |
| |
|
static |
static int check_smf_saved_correctly |
( |
const smf_t * |
smf, |
|
|
FILE * |
file |
|
) |
| |
|
static |
static void free_buffer |
( |
smf_t * |
smf | ) |
|
|
static |
static int pointers_are_clear |
( |
smf_t * |
smf | ) |
|
|
static |
- Returns
- Nonzero, if all pointers supposed to be NULL are NULL. Triggers assertion if not.
Definition at line 439 of file smf_save.c.
static int smf_append |
( |
smf_t * |
smf, |
|
|
const void * |
buffer, |
|
|
const int |
buffer_length |
|
) |
| |
|
static |
Appends "buffer_length" bytes pointed to by "buffer" to the smf, reallocating storage as needed. Returns 0 if everything went ok, different value if there was any problem.
Definition at line 88 of file smf_save.c.
- Returns
- Nonzero, if event is End Of Track metaevent.
Definition at line 467 of file smf_save.c.
smf_event_t* smf_event_new_textual |
( |
int |
type, |
|
|
const char * |
text |
|
) |
| |
static void* smf_extend |
( |
smf_t * |
smf, |
|
|
const int |
length |
|
) |
| |
|
static |
Extends (reallocates) smf->file_buffer and returns pointer to the newly added space, that is, pointer to the first byte after the previous buffer end. Returns NULL in case of error.
Definition at line 58 of file smf_save.c.
int smf_format_vlq |
( |
unsigned char * |
buf, |
|
|
int |
length, |
|
|
unsigned long |
value |
|
) |
| |
int smf_save |
( |
smf_t * |
smf, |
|
|
FILE * |
file |
|
) |
| |
Writes the contents of SMF to the file given.
- Parameters
-
smf | SMF. |
file | File descriptor. |
- Returns
- 0, if saving was successfull.
Definition at line 623 of file smf_save.c.
static int smf_validate |
( |
smf_t * |
smf | ) |
|
|
static |
Check if SMF is valid and add missing EOT events.
- Returns
- 0, if SMF is valid.
Definition at line 484 of file smf_save.c.
static int track_append |
( |
smf_track_t * |
track, |
|
|
const void * |
buffer, |
|
|
const int |
buffer_length |
|
) |
| |
|
static |
Appends "buffer_length" bytes pointed to by "buffer" to the track, reallocating storage as needed. Returns 0 if everything went ok, different value if there was any problem.
Definition at line 148 of file smf_save.c.
static void* track_extend |
( |
smf_track_t * |
track, |
|
|
const int |
length |
|
) |
| |
|
static |
Extends (reallocates) track->file_buffer and returns pointer to the newly added space, that is, pointer to the first byte after the previous buffer end. Returns NULL in case of error.
Definition at line 126 of file smf_save.c.
static int write_escaped_event_contents |
( |
smf_event_t * |
event | ) |
|
|
static |
Appends contents of event->midi_buffer wrapped into 0xF7 MIDI event.
Definition at line 287 of file smf_save.c.
Appends contents of event->midi_buffer. Returns 0 if everything went 0, different value in case of error.
Definition at line 315 of file smf_save.c.
Appends event time as Variable Length Quantity. Returns 0 if everything went ok, different value in case of error.
Definition at line 252 of file smf_save.c.
static int write_file |
( |
smf_t * |
smf, |
|
|
FILE * |
stream |
|
) |
| |
|
static |
Takes smf->file_buffer and saves it to the file.
Definition at line 402 of file smf_save.c.
static int write_mthd_header |
( |
smf_t * |
smf | ) |
|
|
static |
Appends MThd header to the track. Returns 0 if everything went ok, different value if not.
Definition at line 107 of file smf_save.c.
Updates MTrk chunk length of a given track.
Definition at line 359 of file smf_save.c.
static int write_vlq |
( |
smf_event_t * |
event, |
|
|
unsigned long |
value |
|
) |
| |
|
static |
Appends value, expressed as Variable Length Quantity, to event->track.
Definition at line 237 of file smf_save.c.