summaryrefslogtreecommitdiff
path: root/drivers/chibi/cp_player_data_control.cpp
blob: 4d30c1a703894b7a52414eb9751980ef55fad611 (plain)
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*************************************************************************/
/*  cp_player_data_control.cpp                                           */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                    http://www.godotengine.org                         */
/*************************************************************************/
/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur.                 */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/

#include "cp_player_data.h"

void CPPlayer::play_start_pattern(int p_pattern) {

	play_start(p_pattern,-1,-1);
}

void CPPlayer::play_start_song() {

	play_start(-1,-1,-1);
}

void CPPlayer::play_start_song_from_order(int p_order) {

	play_start(-1,p_order,-1);
}

void CPPlayer::play_start_song_from_order_and_row(int p_order,int p_row) {

	play_start(-1,p_order,p_row);
}

void CPPlayer::play_start(int p_pattern, int p_order, int p_row,bool p_lock) {


	if (control.play_mode!=PLAY_NOTHING) play_stop();


	reset();

        if (p_pattern!=-1) {

		control.play_mode=PLAY_PATTERN;
		control.position.current_pattern=p_pattern;
		control.position.current_row=(p_row!=-1)?p_row:0;

	} else {
	
		control.position.current_order=get_song_next_order_idx(song,(p_order==-1)?p_order:p_order-1);
		if (control.position.current_order!=-1) {

			control.play_mode=PLAY_SONG;
			control.position.current_pattern=song->get_order(control.position.current_order);
			control.position.current_row=(p_row!=-1)?p_row:0;
		} 
	}


	control.reached_end=(control.play_mode==PLAY_NOTHING);
	
	
}

void CPPlayer::play_stop() {

	int i;


	control.play_mode=PLAY_NOTHING;

	for (i=0;i<control.max_voices;i++) {

		voice[i].reset();
		mixer->stop_voice(i);
	}

	for (i=0;i<CPPattern::WIDTH;i++) {

		control.channel[i].reset();
	}

	reset();

}

void CPPlayer::play_note(int p_channel,CPNote note,bool p_reserve) {



        if (control.play_mode==PLAY_NOTHING) {

		control.ticks_counter=0;
	}

	/*control.channel[p_channel].reset();
	control.channel[p_channel].channel_volume=song->get_channel_volume(p_channel);
	control.channel[p_channel].channel_panning=((int)song->get_channel_pan( p_channel)*255/64);*/
	if (p_reserve) {
		control.channel[p_channel].mute=false;
		control.channel[p_channel].reserved=true;
	} else {
		
		control.channel[p_channel].reserved=false;
		
	}
	process_note(p_channel,note);



}


int CPPlayer::get_voice_volume(int p_voice) {
	
	return voice[p_voice].display_volume;
}


int CPPlayer::get_voice_envelope_pos(int p_voice,CPEnvelope *p_envelope) {

	int i,tmp_index=-1;

	i=p_voice;




	if ((song->has_instruments()) && (voice[i].instrument_ptr!=NULL) && (voice[i].fadeout_volume>0)) {

		if ((p_envelope==voice[i].instrument_ptr->get_volume_envelope()) && (voice[i].instrument_ptr->get_volume_envelope()->is_enabled())) {

			tmp_index=voice[i].volume_envelope_ctrl.pos_index;
		}

		if ((p_envelope==voice[i].instrument_ptr->get_pan_envelope()) && (voice[i].instrument_ptr->get_pan_envelope()->is_enabled())) {

			tmp_index=voice[i].panning_envelope_ctrl.pos_index;
		}

		if ((p_envelope==voice[i].instrument_ptr->get_pitch_filter_envelope()) && (voice[i].instrument_ptr->get_pitch_filter_envelope()->is_enabled())) {
		

			tmp_index=voice[i].pitch_envelope_ctrl.pos_index;
		}

	}



	return tmp_index;
}

void CPPlayer::goto_next_order() {


	if (control.play_mode!=PLAY_SONG) return;



	control.position.current_row=0;


	control.position.current_order=get_song_next_order_idx(song, control.position.current_order);



	if (control.position.current_order==-1) {

         	reset();	
	}

	control.position.current_pattern=song->get_order(control.position.current_order); 	


}
void CPPlayer::goto_previous_order() {

	if (control.play_mode!=PLAY_SONG) return;


	int next_order,current_order;

	control.position.current_row=0;

	current_order=control.position.current_order;

	next_order=get_song_next_order_idx(song, current_order);

	while ((next_order!=control.position.current_order) && (next_order!=-1)) {

		current_order=next_order;
		next_order=get_song_next_order_idx(song, current_order);
	}

	if (next_order==-1) {

         	reset();	
	} else {

		control.position.current_order=current_order;
	        control.position.current_pattern=song->get_order(control.position.current_order);

	}



}

int CPPlayer::get_channel_voice(int p_channel) {

	if (control.channel[p_channel].slave_voice==NULL) return -1;
	else return control.channel[p_channel].slave_voice_index;
}

const char* CPPlayer::get_voice_sample_name(int p_voice) {

	const char *name;



	if (!voice[p_voice].sample_ptr) name=voice[p_voice].sample_ptr->get_name();



	return name;

}


bool CPPlayer::is_voice_active(int p_voice) {

	return !( ((voice[p_voice].kick==KICK_NOTHING)||(voice[p_voice].kick==KICK_ENVELOPE))&&!mixer->is_voice_active(p_voice) ); 
		
}		
		


int CPPlayer::get_voice_envelope_pos(int p_voice,CPInstrument::EnvelopeType p_env_type) {
	
	if (!is_voice_active(p_voice))
		return -1;
	
	Voice_Control::Envelope_Control *env=0;
	
	switch (p_env_type) {
		
		case CPInstrument::VOLUME_ENVELOPE: env=&voice[p_voice].volume_envelope_ctrl; break;
		case CPInstrument::PAN_ENVELOPE: env=&voice[p_voice].panning_envelope_ctrl; break;
		case CPInstrument::PITCH_ENVELOPE: env=&voice[p_voice].pitch_envelope_ctrl; break;
	
	}
	
	if (!env)
		return -1;
	
	if (!env->active || env->terminated)
		return -1;
	
	return env->pos_index;
}


CPEnvelope* CPPlayer::get_voice_envelope(int p_voice,CPInstrument::EnvelopeType p_env_type) {
	
	CPInstrument *ins=voice[p_voice].instrument_ptr;
	
	if (!ins)
		return 0;
	
	switch( p_env_type ) {
		
		
		case CPInstrument::VOLUME_ENVELOPE: return ins->get_volume_envelope(); 
		case CPInstrument::PAN_ENVELOPE: return ins->get_pan_envelope(); 
		case CPInstrument::PITCH_ENVELOPE: return ins->get_pitch_filter_envelope();
	};
	
	return 0;
		
}

const char * CPPlayer::get_voice_instrument_name(int p_voice) {



	const char *name;



	if (voice[p_voice].instrument_ptr!=NULL) name=voice[p_voice].instrument_ptr->get_name();



	return name;

}
void CPPlayer::set_filters_enabled(bool p_enable){

	control.filters=p_enable;
}

int CPPlayer::get_voice_sample_index(int p_voice) {

	return voice[p_voice].sample_index;
}