2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* cp_player_data.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
CPPlayer::CPPlayer(CPMixer *p_mixer, CPSong *p_song) {
|
|
|
|
|
|
|
|
song = p_song;
|
|
|
|
mixer = p_mixer;
|
|
|
|
control.max_voices = p_mixer->get_total_voice_count() - 1; //leave one for the sample
|
|
|
|
control.force_no_nna = false;
|
|
|
|
control.external_vibrato = false;
|
|
|
|
control.filters = true;
|
|
|
|
control.random_seed = 128364; //anything
|
|
|
|
control.play_mode = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
set_virtual_channels(p_mixer->get_total_voice_count());
|
2017-03-19 00:36:26 +01:00
|
|
|
mixer->set_callback(&CPPlayer::callback_function, this);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
reset();
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
CPPlayer::~CPPlayer() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPPlayer::set_virtual_channels(int p_amount) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_amount < 1) return;
|
|
|
|
if (p_amount > mixer->get_total_voice_count())
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
control.max_voices = p_amount;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPPlayer::callback_function(void *p_userdata) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
CPPlayer *pd = (CPPlayer *)p_userdata;
|
|
|
|
pd->process_tick();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPPlayer::process_tick() {
|
|
|
|
|
|
|
|
handle_tick();
|
2017-03-19 00:36:26 +01:00
|
|
|
mixer->set_callback_interval(2500000 / control.tempo);
|
|
|
|
song_usecs += 2500000 / control.tempo;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPPlayer::reset() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (mixer == NULL) return;
|
|
|
|
if (song == NULL) return;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (i = 0; i < control.max_voices; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
voice[i].reset();
|
2014-02-10 02:10:30 +01:00
|
|
|
mixer->stop_voice(i);
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (i = 0; i < CPPattern::WIDTH; i++) {
|
|
|
|
|
|
|
|
control.channel[i].reset();
|
|
|
|
control.channel[i].channel_volume = song->get_channel_volume(i);
|
|
|
|
control.channel[i].channel_panning = ((int)song->get_channel_pan(i) * PAN_RIGHT / 64);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (song->is_channel_surround(i))
|
2017-03-19 00:36:26 +01:00
|
|
|
control.channel[i].channel_panning = PAN_SURROUND;
|
|
|
|
control.channel[i].mute = song->is_channel_mute(i);
|
|
|
|
control.channel[i].chorus_send = song->get_channel_chorus(i) * 0xFF / 64;
|
|
|
|
control.channel[i].reverb_send = song->get_channel_reverb(i) * 0xFF / 64;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
control.speed = song->get_speed();
|
|
|
|
control.tempo = song->get_tempo();
|
|
|
|
control.global_volume = song->get_global_volume();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
control.position.current_pattern = 0;
|
|
|
|
control.position.current_row = 0;
|
|
|
|
control.position.current_order = 0;
|
|
|
|
control.position.force_next_order = -1;
|
|
|
|
control.ticks_counter = control.speed;
|
|
|
|
control.position.forbid_jump = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
song_usecs = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int64_t CPPlayer::get_channel_last_note_time_usec(int p_channel) const {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
CP_FAIL_INDEX_V(p_channel, 64, -1);
|
2014-02-10 02:10:30 +01:00
|
|
|
return control.channel[p_channel].last_event_usecs;
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void CPPlayer::set_channel_global_volume(int p_channel, int p_volume) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
CP_FAIL_INDEX(p_channel, 64);
|
|
|
|
control.channel[p_channel].channel_global_volume = CLAMP(p_volume, 0, 255);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int CPPlayer::get_channel_global_volume(int p_channel) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
CP_FAIL_INDEX_V(p_channel, 64, -1);
|
2014-02-10 02:10:30 +01:00
|
|
|
return control.channel[p_channel].channel_global_volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPPlayer::reached_end_of_song() {
|
|
|
|
|
|
|
|
return control.reached_end;
|
|
|
|
}
|
|
|
|
void CPPlayer::set_force_external_vibratos(bool p_force) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
control.external_vibrato = p_force;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
void CPPlayer::set_force_no_nna(bool p_force) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
control.force_no_nna = p_force;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|