/* playback.c * Midi playback for a specific portion of * a score * * (c) 2000-2005 Adam Tee */ #include #include "exportmudela.h" #include "exportmidi.h" #include "staffops.h" #include "scoreops.h" #include "dialogs.h" #include "prefops.h" #include "utils.h" #include "external.h" #include #include #include #include #include #include #ifdef HAVE_SYS_WAIT_H #include #endif #ifdef HAVE_WAIT_H #include #endif #include /* start or restart an external midi player * trying avoid multiple instances of it */ void ext_midi_playback (GtkAction * action, DenemoGUI * gui) { GString *mididata = NULL; GString *pidpath = NULL; GString *cmdline = NULL; GPid playerpid = -1; FILE *fp; int got = 0; /* need to by synchronised (one player at a time) */ /* need: singleton access lock (because multiple views) * the old *NIX and *BSD on descriptors : * the SYSV and POSIX on buffered FILE* : */ pidpath = get_temp_filename (ext_pidfiles[EXT_MIDI]); fp = fopen (pidpath->str, "r+"); if (ftrylockfile (fp)) /* might not exist on old BSD's */ { #ifdef DEBUG fprintf (stderr, "ext_midi: another instance is working\n"); #endif /* better chance next time */ fclose (fp); g_string_free (pidpath, TRUE); return; } /* ok, it's our turn: */ got = fscanf (fp, "%d", (int *) &playerpid); rewind (fp); #ifdef DEBUG fprintf (stderr, "ext_midi: got player %d\n", playerpid); #endif /* ensure we got something */ if (got && (playerpid > 0)) { #ifdef DEBUG fprintf (stderr, "ext_midi: killing player: %d\n", playerpid); #endif kill (playerpid, SIGTERM); g_spawn_close_pid (playerpid); /* fix leaks on win32 */ } mididata = get_temp_filename ("denemoplayback.mid"); exportmidi (mididata->str, gui->si, gui->si->start, gui->si->end); cmdline = g_string_new (gui->prefs->midiplayer->str); cmdline = g_string_append (cmdline, "\t"); cmdline = g_string_append (cmdline, mididata->str); playerpid = spawn_external (cmdline); #ifdef DEBUG fprintf (stderr, "ext_midi: spawned %d\n", playerpid); #endif if (playerpid > 0) fprintf (fp, "%d", playerpid); funlockfile (fp); /* might not exist on old BSD's */ fclose (fp); g_string_free (mididata, TRUE); g_string_free (pidpath, TRUE); return; } void playback_local (gpointer callback_data, guint callback_action, GtkWidget * widget) { /* what is it ? */ return; }