42static double seconds_from_pulses(
const smf_t *
smf,
int pulses);
59 return (previous_tempo);
64 g_critical(
"Cannot allocate smf_tempo_t.");
70 if (previous_tempo != NULL) {
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);
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);
308 assert(seconds >= 0.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
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)
Represents a single MIDI event or metaevent.
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.
Represents a "song", that is, collection of one or more tracks.
GPtrArray * tempo_array
Private, used by smf_tempo.c.
int ppqn
These fields are extracted from "division" field of MThd header.
Describes a single tempo or time signature change.
int microseconds_per_quarter_note
Represents a single track.