static int cmd_events(char *notused) { smf_event_t *event; if (selected_track == NULL) { g_critical("No track selected - please use 'track <number>' command first."); return (-1); } if (selected_track->number_of_events == 0) { g_message("Selected track is empty."); return (0); } g_message("List of events in track %d follows:", selected_track->track_number); smf_rewind(smf); while ((event = smf_track_get_next_event(selected_track)) != NULL) show_event(event); smf_rewind(smf); return (0); }
/** * Seeks the SMF to the given event. After calling this routine, smf_get_next_event * will return the event that was the second argument of this call. */ int smf_seek_to_event(smf_t *smf, const smf_event_t *target) { smf_event_t *event; smf_rewind(smf); #if 0 g_debug("Seeking to event %d, track %d.", target->event_number, target->track->track_number); #endif for (;;) { event = smf_peek_next_event(smf); /* There can't be NULL here, unless "target" is not in this smf. */ assert(event); if (event != target) smf_skip_next_event(smf); else break; } smf->last_seek_position = event->time_seconds; return (0); }
/** * Seeks the SMF to the given position. For example, after seeking to 10 pulses, * smf_get_next_event will return first event that happens after the first ten pulses. * \return 0 if everything went ok, nonzero otherwise. */ int smf_seek_to_pulses(smf_t *smf, int pulses) { smf_event_t *event; assert(pulses >= 0); smf_rewind(smf); #if 0 g_debug("Seeking to %d pulses.", pulses); #endif for (;;) { event = smf_peek_next_event(smf); if (event == NULL) { g_critical("Trying to seek past the end of song."); return (-1); } if (event->time_pulses < pulses) smf_skip_next_event(smf); else break; } smf->last_seek_position = event->time_seconds; return (0); }
void start_playing (gchar * callback) { smf_t *smf = Denemo.project->movement->smf; if (callback && *callback) callback_script = g_string_new (callback); if (Denemo.project->movement->recorded_midi_track) safely_add_track (Denemo.project->movement->smf, Denemo.project->movement->recorded_midi_track); fix_start_end_ordering (); smf_rewind (smf); gdouble start = (Denemo.project->movement->start_time/get_playback_speed()) - SHAVING; if(smf_seek_to_seconds (smf, (start>0.0)?start:0.0)) g_warning("smf_seek_to_seconds %f failed", start); initialize_until_time (); initialize_playhead (); playing = TRUE; last_draw_time = -1.0;//needed to trigger drawing first note }
/** * Loads SMF file. * * \param file Open file. * \return SMF or NULL, if loading failed. */ smf_t * smf_load(FILE *file) { size_t file_buffer_length; void *file_buffer; smf_t *smf; if (load_file_into_buffer(&file_buffer, &file_buffer_length, file)) return (NULL); smf = smf_load_from_memory(file_buffer, file_buffer_length); memset(file_buffer, 0, file_buffer_length); free(file_buffer); if (smf == NULL) return (NULL); smf_rewind(smf); return (smf); }
/** * Seeks the SMF to the given position. For example, after seeking to 1.0 seconds, * smf_get_next_event will return first event that happens after the first second of song. * \return 0 if everything went ok, nonzero otherwise. */ int smf_seek_to_seconds(smf_t *smf, double seconds) { smf_event_t *event; assert(seconds >= 0.0); if (seconds == smf->last_seek_position) { #if 0 g_debug("Avoiding seek to %f seconds.", seconds); #endif return (0); } smf_rewind(smf); #if 0 g_debug("Seeking to %f seconds.", seconds); #endif for (;;) { event = smf_peek_next_event(smf); if (event == NULL) { g_critical("Trying to seek past the end of song."); return (-1); } if (event->time_seconds < seconds) smf_skip_next_event(smf); else break; } smf->last_seek_position = seconds; return (0); }
gboolean writer_timeout (gpointer file_name_gpointer) { int i; char * file_name = (char *) file_name_gpointer; /* * XXX: It should be done like this: * http://wwwtcs.inf.tu-dresden.de/~tews/Gtk/x2992.html */ if (ctrl_c_pressed == 0) return TRUE; jack_deactivate(jack_client); smf_rewind(smf); /* Get rid of empty tracks. */ for (i = 0; i < 16; ++i) { if (tracks[i]->number_of_events == 0) { smf_remove_track(tracks[i]); smf_track_delete(tracks[i]); } } if (smf->number_of_tracks == 0) { g_message("No events recorded, not saving anything."); exit(0); } if (smf_save(smf, file_name)) { g_critical("Could not save file '%s', sorry.", file_name); exit(-1); } g_message("File '%s' saved successfully.", file_name); exit(0); }