CAMLprim value ocaml_smf_save(value smf, value file) { CAMLparam2(smf, file); int ret; ret = smf_save(Smf_val(smf), String_val(file)); CAMLreturn(Val_bool(ret)); }
static int cmd_save(char *file_name) { int ret; if (file_name == NULL) { if (last_file_name == NULL) { g_critical("Please specify file name."); return (-1); } file_name = strdup(last_file_name); } else { file_name = strdup(file_name); } if (last_file_name != NULL) free(last_file_name); last_file_name = strdup(file_name); ret = smf_save(smf, file_name); if (ret) { g_critical("Couldn't save '%s'", file_name); return (-1); } g_message("File '%s' saved.", file_name); free(file_name); 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); }
G_MODULE_EXPORT void on_doIt_clicked( GtkButton *button, gpointer data ) { printf("button clicked\n"); smf_t* smf = smf_new(); smf_track_t* track = smf_track_new(); smf_add_track(smf, track); smf_event_t* event; gboolean prevFrame[NUMBER_OF_KEYS] = { FALSE }; // Start video from beginning currentFrame = startFrame; //upper 9 notes have lyrics //2920 start while (currentFrame <= stopFrame) { int i = 0; if ( currentFrame == stopFrame ) { for (i = 0; i < NUMBER_OF_KEYS; i++ ) { noteOn[i] = FALSE; } } else { redrawFrame(); } // Why NUMBER_OF_KEYS - 10? Well, the lyrics in my example are printed across // the upper 10 notes and were being detected as notes themselves, causing odd // trilling when they scrolled past. This was a quick hack to make that stop. for ( i = 0; i < NUMBER_OF_KEYS - 10; i++ ) { char note = 0xd + i; char eventBytes[3] = { 0 }; eventBytes[1] = note; // which note to play eventBytes[2] = 0x7f; // full velocity (may toy with later) if (prevFrame[i] && (!noteOn[i])) { // Time to generate a note-off eventBytes[0] = 0x80; printf("note-off: %x, at frame %f\n", i + 0xd, currentFrame); } if ((!prevFrame[i]) && noteOn[i]) { // Time to generate a note-on eventBytes[0] = 0x90; printf("note-on: %x, at frame %f\n", i + 0xd, currentFrame); } prevFrame[i] = noteOn[i]; if ( eventBytes[0] ) { event = smf_event_new_from_pointer(eventBytes, 3); smf_track_add_event_seconds(track, event, currentFrame / 30.0); } } currentFrame++; gtk_main_iteration_do( FALSE ); } smf_save(smf, "output.mid"); }
static int ui_save_state(ui_t *ui, char *filename) { int i; smf_t *smf; smf_track_t *track; jack_nframes_t frame; double seconds; list_t *pattern, *lp; note_t *note; /* TODO: check if file exists */ if (!filename) { filename = ui_get_filename(ui, ".", "Save to: "); } ui->filename = filename; smf = smf_new(); if (!smf) { return 0; } for (i = 0; i < 8; i++) { track = smf_track_new(); if (!track) { smf_delete(smf); return 0; } smf_add_track(smf, track); pattern = ui->patterns[i]; if (!pattern) { continue; } for (lp = pattern; lp; lp = list_next(lp)) { note = (note_t *)list_data(lp); frame = 88200 / ui->steps * note->step; seconds = ui_nframes_to_seconds(ui, frame); note_event_save(note, track, 0x90, seconds); /* TODO: decide if and how noteoffs should be saved */ /* frame = 88200 / ui->steps */ /* * ((note->step + note->len) % ui->steps); */ /* seconds = ui_nframes_to_seconds(ui, frame); */ /* note_event_save(note, track, NOTEOFF, seconds); */ } if (smf_track_add_eot_seconds(track, 2)) { return 0; } } if (smf_save(smf, ui->filename)) { return 0; } return 1; }