42static double seconds_from_pulses(
const smf_t *
smf,
int pulses);
54 if (
smf->tempo_array->len > 0) {
59 return (previous_tempo);
64 g_critical(
"Cannot allocate smf_tempo_t.");
70 if (previous_tempo != NULL) {
84 g_ptr_array_add(
smf->tempo_array, tempo);
95add_tempo(
smf_t *
smf,
int pulses,
int tempo)
98 if (smf_tempo == NULL)
107add_time_signature(
smf_t *
smf,
int pulses,
int numerator,
int denominator,
int clocks_per_click,
int notes_per_note)
110 if (smf_tempo == NULL)
130 assert(event->
track != NULL);
137 g_critical(
"Tempo Change event seems truncated.");
141 int new_tempo = (
event->midi_buffer[3] << 16) + (event->
midi_buffer[4] << 8) +
event->midi_buffer[5];
142 if (new_tempo <= 0) {
143 g_critical(
"Ignoring invalid tempo change.");
152 int numerator, denominator, clocks_per_click, notes_per_note;
155 g_critical(
"Time Signature event seems truncated.");
159 numerator =
event->midi_buffer[3];
161 clocks_per_click =
event->midi_buffer[5];
162 notes_per_note =
event->midi_buffer[6];
164 add_time_signature(event->
track->
smf, event->
time_pulses, numerator, denominator, clocks_per_click, notes_per_note);
186 if (
smf->tempo_array->len == 0)
198 g_ptr_array_remove_index(
smf->tempo_array,
smf->tempo_array->len - 1);
202seconds_from_pulses(
const smf_t *
smf,
int pulses)
218pulses_from_seconds(
const smf_t *
smf,
double seconds)
255 event->time_seconds = seconds_from_pulses(
smf, event->
time_pulses);
266 if (number >=
smf->tempo_array->len)
269 return (g_ptr_array_index(
smf->tempo_array, number));
286 assert(
smf->tempo_array != NULL);
288 for (i =
smf->tempo_array->len - 1; i >= 0; i--) {
308 assert(seconds >= 0.0);
313 assert(
smf->tempo_array != NULL);
315 for (i =
smf->tempo_array->len - 1; i >= 0; i--) {
351 while (
smf->tempo_array->len > 0) {
352 tempo = g_ptr_array_index(
smf->tempo_array,
smf->tempo_array->len - 1);
358 g_ptr_array_remove_index(
smf->tempo_array,
smf->tempo_array->len - 1);
361 assert(
smf->tempo_array->len == 0);
378 tempo = new_tempo(
smf, 0);
380 g_error(
"tempo_init failed, sorry.");
392 assert(previous_event);
413 assert(track->
smf != NULL);
429 assert(track->
smf != NULL);
431 event->time_pulses = pulses;
432 event->time_seconds = seconds_from_pulses(track->
smf, pulses);
444 assert(seconds >= 0.0);
447 assert(track->
smf != NULL);
449 event->time_seconds = seconds;
450 event->time_pulses = pulses_from_seconds(track->
smf, seconds);
void smf_track_add_event(smf_track_t *track, smf_event_t *event)
Adds the event to the track and computes ->delta_pulses.
smf_event_t * smf_track_get_last_event(const smf_track_t *track)
smf_event_t * smf_get_next_event(smf_t *smf)
void smf_rewind(smf_t *smf)
Rewinds the SMF.
Public interface declaration for libsmf, Standard MIDI File format library.
int smf_event_is_metadata(const smf_event_t *event) WARN_UNUSED_RESULT
struct smf_event_struct smf_event_t
struct smf_track_struct smf_track_t
struct smf_tempo_struct smf_tempo_t
void maybe_add_to_tempo_map(smf_event_t *event)
void smf_track_add_event_pulses(smf_track_t *track, smf_event_t *event, int pulses)
Adds event to the track at the time "pulses" clocks from the start of song.
void smf_init_tempo(smf_t *smf)
void smf_create_tempo_map_and_compute_seconds(smf_t *smf)
smf_tempo_t * smf_get_tempo_by_seconds(const smf_t *smf, double seconds)
Return last tempo (i.e.
void remove_last_tempo_with_pulses(smf_t *smf, int pulses)
smf_tempo_t * smf_get_tempo_by_pulses(const smf_t *smf, int pulses)
Return last tempo (i.e.
void smf_fini_tempo(smf_t *smf)
void smf_track_add_event_seconds(smf_track_t *track, smf_event_t *event, double seconds)
Adds event to the track at the time "seconds" seconds from the start of song.
smf_tempo_t * smf_get_last_tempo(const smf_t *smf)
Return last tempo.
void smf_track_add_event_delta_pulses(smf_track_t *track, smf_event_t *event, int delta)
Adds event to the track at the time "pulses" clocks from the previous event in this track.
smf_tempo_t * smf_get_tempo_by_number(const smf_t *smf, int number)
int time_pulses
Time, in pulses, since the start of the song.
unsigned char * midi_buffer
Pointer to the buffer containing MIDI message.
double time_seconds
Time, in seconds, since the start of the song.
int midi_buffer_length
Length of the MIDI message in the buffer, in bytes.
smf_track_t * track
Pointer to the track, or NULL if event is not attached.
int microseconds_per_quarter_note