1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/* playback.c
* Midi playback for a specific portion of
* a score
*
* (c) 2000, 2001 Adam Tee
*/
#include "datastructures.h"
#include "exportmudela.h"
#include "exportmidi.h"
#include "staffops.h"
#include "scoreops.h"
#include "dialogs.h"
#include "prefops.h"
#include "utils.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#ifndef G_OS_WIN32
# include <wait.h>
#endif
#include <errno.h>
void
playback (gpointer callback_data, guint callback_action, GtkWidget * widget)
{
static GString *filename = NULL;
static GString *passtosystem;
pid_t pid;
struct scoreinfo *si = callback_data;
if (!filename)
{
filename = g_string_new (locatedotdenemo ());
g_string_append (filename, "/denemoplayback");
passtosystem = g_string_new (NULL);
}
#ifdef G_OS_WIN32
pid = -1;
#else
pid = fork ();
#endif
if (pid == -1)
{
/*
* Fork failed to create a process :
*/
fprintf (stderr, "%s: Failed to fork()\n", strerror (errno));
return;
}
else if (pid == 0)
{
int status = 0;
if (si->prefs->playbackoutput)
{
exportmidi (filename->str, si, si->start, si->end);
fflush (0);
}
else
{
/*
* This is the child process, which exports the mudela, invokes
* lilypond, then invokes the midi player
*/
exportmudela (filename->str, si, si->start, si->end);
/* Invoke lilypond */
g_string_assign (passtosystem, si->prefs->lilypath->str);
g_string_append (passtosystem, " -o ");
g_string_append (passtosystem, filename->str);
g_string_append (passtosystem, " -m ");
g_string_append (passtosystem, filename->str);
g_string_append (passtosystem, ".ly");
status = system (passtosystem->str);
}
/* Invoke the midi player */
if(!status) {
g_string_assign (passtosystem, si->prefs->midiplayer->str);
g_string_append (passtosystem, " ");
g_string_append (passtosystem, filename->str);
g_string_append (passtosystem, ".midi");
system (passtosystem->str);
}
_exit (0);
}
/* Otherwise, this is the parent process, in which case we simply
* want to return the user to his or her regularly scheduled
* music-making */
}
|