/* Artword_Speaker_Sound.c */
/* Paul Boersma, August 2, 2001 */

#include "Artword_Speaker_Sound.h"
#include "Artword_Speaker.h"
#include "Art_Speaker.h"

struct playInfo {
	Artword artword;
	Speaker speaker;
	Graphics graphics;
};

static int playCallback (void *playClosure, int phase, double tmin, double tmax, double t) {
	struct playInfo *me = (struct playInfo *) playClosure;
	static Art art;
	(void) phase;
	(void) tmin;
	(void) tmax;
	if (! art) art = Art_create ();
	Artword_intoArt (my artword, art, t);
	Graphics_clearWs (my graphics);
	Art_Speaker_draw (art, my speaker, my graphics);
	return 1;
}

void Artword_Speaker_Sound_movie (Artword artword, Speaker speaker, Sound sound, Graphics graphics) {
	int own = FALSE;
	static struct playInfo info;   /* Must be static!!! */
	info. artword = artword;
	info. speaker = speaker;
	info. graphics = graphics;
	if (sound == NULL) {
		sound = Sound_createSimple (artword -> totalTime, 22050);
		if (! sound) {
			Melder_flushError (NULL);
			return;
		}
		own = TRUE;
	}
	Sound_play (sound, playCallback, & info);
	if (own) {
		forget (sound);
	}
}

/* End of file Artword_Speaker_Sound.c */
