cp_player_data_control.cpp 7.7 KB

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