File: playlist.c

package info (click to toggle)
mlv 3.1.0-8
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 10,596 kB
  • sloc: ansic: 18,982; sh: 4,760; makefile: 381; objc: 246; xml: 92
file content (205 lines) | stat: -rw-r--r-- 4,884 bytes parent folder | download | duplicates (3)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 *   This file is part of the MLV Library.
 *
 *   Copyright (C) 2010,2011,2012 Adrien Boussicault, Marc Zipstein
 *
 *
 *    This Library is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This Library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this Library.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "MLV_playlist.h"

#include "MLV_audio.h"

#include "data_structure.h"
#include "list.h"
#include "memory_management.h"

#include "warning_error.h"

#ifndef MEMORY_DEBUG
#include <SDL/SDL.h>
#else
#include "memory_debug.h"
#endif

extern DataMLV* MLV_data;

typedef struct _Music_item {
	int interne;
	MLV_Music* music;
} Music_item;

struct _MLV_Playlist {
	MLV_List* music_items;
	int playing;
	int current;
	int size;
	SDL_sem* semaphore;
	double volume;
	int loop;
};

void MLV_init_playlists(){
	MLV_data->playlists = NULL;
	MLV_data->active_playlists = NULL;
}

void MLV_close_playlists(){
    MLV_List* playlists = NULL;
	MLV_List* tmp = MLV_data->playlists;
	while(tmp){
		playlists = MLV_prepend_list(
			playlists,
			tmp->data	
		);
		tmp = tmp->next;
	}
	MLV_foreach_list(
		playlists,
		(void (*)(void*,void*)) MLV_close_playlist
		, NULL
	);
    MLV_free_list( MLV_data->playlists );
    MLV_free_list( MLV_data->active_playlists );
}

MLV_Playlist* MLV_create_playlist( int loop ){
	MLV_Playlist* playlist = MLV_MALLOC( 1, MLV_Playlist );
	playlist->music_items = NULL;
    playlist->semaphore = SDL_CreateSemaphore(1);
	playlist->volume = 1.0;
	playlist->size = 0;
	playlist->loop = loop;
	if( SDL_SemWait( MLV_data->audio_semaphore )  ){
		ERROR_FULL("Probleme de semaphore");
	}
	MLV_data->playlists = MLV_prepend_list(
		MLV_data->playlists,
		playlist	
	);
	if( SDL_SemPost( MLV_data->audio_semaphore ) ){
		ERROR_FULL("Probleme de semaphore");
	}
	return playlist;
}

void MLV_close_playlist( MLV_Playlist* playlist ){
	if( SDL_SemWait( MLV_data->audio_semaphore )  ){
		ERROR_FULL("Probleme de semaphore");
	}
	MLV_data->playlists = MLV_remove_list( MLV_data->playlists, playlist );
	if( SDL_SemPost( MLV_data->audio_semaphore ) ){
		ERROR_FULL("Probleme de semaphore");
	}
	MLV_playlist_clear( playlist );
    MLV_free_list( playlist->music_items );
    SDL_DestroySemaphore( playlist->semaphore );
}

void MLV_playlist_add( MLV_Playlist* playlist, const char* file_music ){
	Music_item* item = MLV_MALLOC(1, Music_item);
	item->interne = 1;
	item->music = MLV_load_music( file_music );
	if( SDL_SemWait( playlist->semaphore )  ){
		ERROR_FULL("Probleme de semaphore");
	}
	playlist->music_items = MLV_prepend_list(
		playlist->music_items,
		item
	);
	playlist->size ++;
	if( SDL_SemPost( playlist->semaphore ) ){
		ERROR_FULL("Probleme de semaphore");
	}
}

void MLV_playlist_add_sheet_music( MLV_Playlist* playlist, MLV_Music* music ){
	Music_item* item = MLV_MALLOC(1, Music_item);
	item->interne = 0;
	item->music = music;
	if( SDL_SemWait( playlist->semaphore )  ){
		ERROR_FULL("Probleme de semaphore");
	}
	playlist->music_items = MLV_prepend_list(
		playlist->music_items,
		item
	);
	if( SDL_SemPost( playlist->semaphore ) ){
		ERROR_FULL("Probleme de semaphore");
	}
}

void MLV_playlist_remove( MLV_Playlist* playlist, int index ){
	TODO
}

void MLV_playlist_clear( MLV_Playlist* playlist ){
	TODO
}

void MLV_playlist_volume( MLV_Playlist* playlist, double volume ){
	if( SDL_SemWait( playlist->semaphore )  ){
		ERROR_FULL("Probleme de semaphore");
	}
	playlist->volume = volume;
	if( SDL_SemPost( playlist->semaphore ) ){
		ERROR_FULL("Probleme de semaphore");
	}
}

void MLV_playlist_play( MLV_Playlist* playlist ){
	if( SDL_SemWait( playlist->semaphore )  ){
		ERROR_FULL("Probleme de semaphore");
	}
	playlist->playing = 1;
	if( SDL_SemPost( playlist->semaphore ) ){
		ERROR_FULL("Probleme de semaphore");
	}
}

void MLV_playlist_pause( MLV_Playlist* playlist ){
	if( SDL_SemWait( playlist->semaphore )  ){
		ERROR_FULL("Probleme de semaphore");
	}
	playlist->playing = 0;
	if( SDL_SemPost( playlist->semaphore ) ){
		ERROR_FULL("Probleme de semaphore");
	}
}

void MLV_playlist_stop( MLV_Playlist* playlist ){
	TODO
}

void MLV_playlist_next( MLV_Playlist* playlist ){
	TODO
}

void MLV_playlist_previous( MLV_Playlist* playlist ){
	TODO
}

void MLV_playlist_first( MLV_Playlist* playlist ){
	TODO
}

void MLV_playlist_last( MLV_Playlist* playlist ){
	TODO
}

void MLV_playlist_index( MLV_Playlist* playlist, int index){
	TODO
}