cp_player_data_control.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*************************************************************************/
  2. /* cp_player_data_control.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "cp_player_data.h"
  31. void CPPlayer::play_start_pattern(int p_pattern) {
  32. play_start(p_pattern, -1, -1);
  33. }
  34. void CPPlayer::play_start_song() {
  35. play_start(-1, -1, -1);
  36. }
  37. void CPPlayer::play_start_song_from_order(int p_order) {
  38. play_start(-1, p_order, -1);
  39. }
  40. void CPPlayer::play_start_song_from_order_and_row(int p_order, int p_row) {
  41. play_start(-1, p_order, p_row);
  42. }
  43. void CPPlayer::play_start(int p_pattern, int p_order, int p_row, bool p_lock) {
  44. if (control.play_mode != PLAY_NOTHING) play_stop();
  45. reset();
  46. if (p_pattern != -1) {
  47. control.play_mode = PLAY_PATTERN;
  48. control.position.current_pattern = p_pattern;
  49. control.position.current_row = (p_row != -1) ? p_row : 0;
  50. } else {
  51. control.position.current_order = get_song_next_order_idx(song, (p_order == -1) ? p_order : p_order - 1);
  52. if (control.position.current_order != -1) {
  53. control.play_mode = PLAY_SONG;
  54. control.position.current_pattern = song->get_order(control.position.current_order);
  55. control.position.current_row = (p_row != -1) ? p_row : 0;
  56. }
  57. }
  58. control.reached_end = (control.play_mode == PLAY_NOTHING);
  59. }
  60. void CPPlayer::play_stop() {
  61. int i;
  62. control.play_mode = PLAY_NOTHING;
  63. for (i = 0; i < control.max_voices; i++) {
  64. voice[i].reset();
  65. mixer->stop_voice(i);
  66. }
  67. for (i = 0; i < CPPattern::WIDTH; i++) {
  68. control.channel[i].reset();
  69. }
  70. reset();
  71. }
  72. void CPPlayer::play_note(int p_channel, CPNote note, bool p_reserve) {
  73. if (control.play_mode == PLAY_NOTHING) {
  74. control.ticks_counter = 0;
  75. }
  76. /*control.channel[p_channel].reset();
  77. control.channel[p_channel].channel_volume=song->get_channel_volume(p_channel);
  78. control.channel[p_channel].channel_panning=((int)song->get_channel_pan( p_channel)*255/64);*/
  79. if (p_reserve) {
  80. control.channel[p_channel].mute = false;
  81. control.channel[p_channel].reserved = true;
  82. } else {
  83. control.channel[p_channel].reserved = false;
  84. }
  85. process_note(p_channel, note);
  86. }
  87. int CPPlayer::get_voice_volume(int p_voice) {
  88. return voice[p_voice].display_volume;
  89. }
  90. int CPPlayer::get_voice_envelope_pos(int p_voice, CPEnvelope *p_envelope) {
  91. int i, tmp_index = -1;
  92. i = p_voice;
  93. if ((song->has_instruments()) && (voice[i].instrument_ptr != NULL) && (voice[i].fadeout_volume > 0)) {
  94. if ((p_envelope == voice[i].instrument_ptr->get_volume_envelope()) && (voice[i].instrument_ptr->get_volume_envelope()->is_enabled())) {
  95. tmp_index = voice[i].volume_envelope_ctrl.pos_index;
  96. }
  97. if ((p_envelope == voice[i].instrument_ptr->get_pan_envelope()) && (voice[i].instrument_ptr->get_pan_envelope()->is_enabled())) {
  98. tmp_index = voice[i].panning_envelope_ctrl.pos_index;
  99. }
  100. if ((p_envelope == voice[i].instrument_ptr->get_pitch_filter_envelope()) && (voice[i].instrument_ptr->get_pitch_filter_envelope()->is_enabled())) {
  101. tmp_index = voice[i].pitch_envelope_ctrl.pos_index;
  102. }
  103. }
  104. return tmp_index;
  105. }
  106. void CPPlayer::goto_next_order() {
  107. if (control.play_mode != PLAY_SONG) return;
  108. control.position.current_row = 0;
  109. control.position.current_order = get_song_next_order_idx(song, control.position.current_order);
  110. if (control.position.current_order == -1) {
  111. reset();
  112. }
  113. control.position.current_pattern = song->get_order(control.position.current_order);
  114. }
  115. void CPPlayer::goto_previous_order() {
  116. if (control.play_mode != PLAY_SONG) return;
  117. int next_order, current_order;
  118. control.position.current_row = 0;
  119. current_order = control.position.current_order;
  120. next_order = get_song_next_order_idx(song, current_order);
  121. while ((next_order != control.position.current_order) && (next_order != -1)) {
  122. current_order = next_order;
  123. next_order = get_song_next_order_idx(song, current_order);
  124. }
  125. if (next_order == -1) {
  126. reset();
  127. } else {
  128. control.position.current_order = current_order;
  129. control.position.current_pattern = song->get_order(control.position.current_order);
  130. }
  131. }
  132. int CPPlayer::get_channel_voice(int p_channel) {
  133. if (control.channel[p_channel].slave_voice == NULL)
  134. return -1;
  135. else
  136. return control.channel[p_channel].slave_voice_index;
  137. }
  138. const char *CPPlayer::get_voice_sample_name(int p_voice) {
  139. const char *name = NULL;
  140. if (!voice[p_voice].sample_ptr) name = voice[p_voice].sample_ptr->get_name();
  141. return name;
  142. }
  143. bool CPPlayer::is_voice_active(int p_voice) {
  144. return !(((voice[p_voice].kick == KICK_NOTHING) || (voice[p_voice].kick == KICK_ENVELOPE)) && !mixer->is_voice_active(p_voice));
  145. }
  146. int CPPlayer::get_voice_envelope_pos(int p_voice, CPInstrument::EnvelopeType p_env_type) {
  147. if (!is_voice_active(p_voice))
  148. return -1;
  149. Voice_Control::Envelope_Control *env = 0;
  150. switch (p_env_type) {
  151. case CPInstrument::VOLUME_ENVELOPE: env = &voice[p_voice].volume_envelope_ctrl; break;
  152. case CPInstrument::PAN_ENVELOPE: env = &voice[p_voice].panning_envelope_ctrl; break;
  153. case CPInstrument::PITCH_ENVELOPE: env = &voice[p_voice].pitch_envelope_ctrl; break;
  154. }
  155. if (!env)
  156. return -1;
  157. if (!env->active || env->terminated)
  158. return -1;
  159. return env->pos_index;
  160. }
  161. CPEnvelope *CPPlayer::get_voice_envelope(int p_voice, CPInstrument::EnvelopeType p_env_type) {
  162. CPInstrument *ins = voice[p_voice].instrument_ptr;
  163. if (!ins)
  164. return 0;
  165. switch (p_env_type) {
  166. case CPInstrument::VOLUME_ENVELOPE: return ins->get_volume_envelope();
  167. case CPInstrument::PAN_ENVELOPE: return ins->get_pan_envelope();
  168. case CPInstrument::PITCH_ENVELOPE: return ins->get_pitch_filter_envelope();
  169. };
  170. return 0;
  171. }
  172. const char *CPPlayer::get_voice_instrument_name(int p_voice) {
  173. const char *name = NULL;
  174. if (voice[p_voice].instrument_ptr != NULL) name = voice[p_voice].instrument_ptr->get_name();
  175. return name;
  176. }
  177. void CPPlayer::set_filters_enabled(bool p_enable) {
  178. control.filters = p_enable;
  179. }
  180. int CPPlayer::get_voice_sample_index(int p_voice) {
  181. return voice[p_voice].sample_index;
  182. }