static void queue_dir(const char *path)
{
	mpd_InfoEntity entity;
	struct ll {
		char *path;
		struct ll *next;
	} *head = 0;

	if (mpdc_tickle() < 0)
		return;

	mpd_sendListallInfoCommand(mpdz, path);

	if (mpdz->error) {
		mpdc_tickle();
		return;
	}
	while ((mpd_getNextInfoEntity_st(&entity, mpdz))) {
		if (entity.type == MPD_INFO_ENTITY_TYPE_SONG) {
			struct ll *it, *ll = calloc(1, sizeof(struct ll));
			mpd_Song *song = entity.info.song;
			if ((it = head)) {
				while (it->next)
					it = it->next;
				it->next = ll;
			} else head = ll;
			ll->path = strdup(song->file);
		}
	}
	mpd_finishCommand(mpdz);
	if (mpdz->error)
		mpdc_tickle();

	while (head) {
		struct ll *o;
		queue_song(head->path);
		free(head->path);
		o = head->next;
		free(head);
		head = o;
	}
}
Exemple #2
0
void music_idle_proc(
	void)
{
	if(music_state && music_state->initialized && music_state->state != _no_song_playing)
	{
		short ticks_elapsed= TickCount()-music_state->ticks_at_last_update;

		switch(music_state->state)
		{
			case _delaying_for_loop:
				if((music_state->phase-=ticks_elapsed)<=0)
				{
					/* Start playing.. */
					OSErr error;

					music_state->sound_buffer_size= kDefaultSoundBufferSize;
					music_state->sound_buffer= (Ptr)malloc(music_state->sound_buffer_size);
					if (music_state->sound_buffer)
					{
						assert(music_state->channel);					
	
						error= SndStartFilePlay(music_state->channel, // channel
							music_state->song_file_refnum, // Not from an AIFF file.
							0, // our resource id.
							music_state->sound_buffer_size, // Buffer size
							music_state->sound_buffer, // Let it allocate a buffer for us.
							NULL, // Audio selection ptr.
							music_state->completion_proc, // Completion proc
							TRUE); // Async.
						vwarn(error==noErr, csprintf(temporary, "SndStartFilePlay returned %d;g", error));
						if (!error) 
						{
							music_state->state= _playing_introduction;
						}
						else
						{
							music_state->state= _no_song_playing;
						}
					}
				}
				break;

			case _music_fading:
				if (ticks_elapsed>0)
				{
					if((music_state->phase-=ticks_elapsed)<=0 || (music_state->flags & _song_completed))
					{
						/* oops. we are done.. */
						stop_music();
						music_state->state= _no_song_playing;
						if(music_state->song_index != NONE)
						{
							/* Start the new song playing.. */
							queue_song(music_state->song_index);
						}
					} else {
						if(--music_state->fade_interval_ticks<=0)
						{
							short new_volume;
							SndCommand command;
							OSErr error;
							
							/* Only do this a few times.. */
							music_state->fade_interval_ticks= music_state->fade_interval_duration;
	
							/* Set the sound volume */
							new_volume= (0x100*music_state->phase)/music_state->fade_duration;

							/* set the sound volume */
							command.cmd= volumeCmd;
							command.param1= 0;
							command.param2= BUILD_STEREO_VOLUME(new_volume, new_volume);
							error= SndDoImmediate(music_state->channel, &command);
							vwarn(error==noErr, csprintf(temporary, "SndDoImmediate returned %d;g", error));
						}
					}
				}
				break;
			
			default:
				/* Don't change states until song_completed flag is set. */
				if(music_state->flags & _song_completed)
				{
					struct song_definition *song= get_song_definition(music_state->song_index);
					
					if(song->flags & _song_automatically_loops)
					{
						music_state->state= _delaying_for_loop;
						music_state->phase= song->restart_delay;
					} else {
						music_state->state= _no_song_playing;
					}
					music_state->flags &= ~_song_completed;
				}
				break;
		}
		music_state->ticks_at_last_update= TickCount();
	}

	return;
}
static void queue_song_item(ttk_menu_item *item)
{
	queue_song(item->data);
}