cp_player_data_nna.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*************************************************************************/
  2. /* cp_player_data_nna.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::process_NNAs() {
  32. int i;
  33. if (!song->has_instruments()) return;
  34. for (i = 0; i < CPPattern::WIDTH; i++) {
  35. Channel_Control *aux_chn_ctrl = &control.channel[i];
  36. if (aux_chn_ctrl->kick == KICK_NOTE) {
  37. bool k = false;
  38. if (aux_chn_ctrl->slave_voice != NULL) {
  39. Voice_Control *aux_voc_ctrl;
  40. aux_voc_ctrl = aux_chn_ctrl->slave_voice;
  41. if (aux_chn_ctrl->instrument_index == aux_chn_ctrl->slave_voice->instrument_index) { //maybe carry
  42. aux_chn_ctrl->carry.pan = aux_chn_ctrl->slave_voice->panning_envelope_ctrl;
  43. aux_chn_ctrl->carry.vol = aux_chn_ctrl->slave_voice->volume_envelope_ctrl;
  44. aux_chn_ctrl->carry.pitch = aux_chn_ctrl->slave_voice->pitch_envelope_ctrl;
  45. aux_chn_ctrl->carry.maybe = true;
  46. } else
  47. aux_chn_ctrl->carry.maybe = false;
  48. if (aux_voc_ctrl->NNA_type != CPInstrument::NNA_NOTE_CUT) {
  49. /* Make sure the old MP_VOICE channel knows it has no
  50. master now ! */
  51. aux_chn_ctrl->slave_voice = NULL;
  52. /* assume the channel is taken by NNA */
  53. aux_voc_ctrl->has_master_channel = false;
  54. switch (aux_voc_ctrl->NNA_type) {
  55. case CPInstrument::NNA_NOTE_CONTINUE: {
  56. } break;
  57. case CPInstrument::NNA_NOTE_OFF: {
  58. aux_voc_ctrl->note_end_flags |= END_NOTE_OFF;
  59. if (!aux_voc_ctrl->volume_envelope_ctrl.active || aux_voc_ctrl->instrument_ptr->get_volume_envelope()->is_loop_enabled()) {
  60. aux_voc_ctrl->note_end_flags |= END_NOTE_FADE;
  61. }
  62. } break;
  63. case CPInstrument::NNA_NOTE_FADE: {
  64. aux_voc_ctrl->note_end_flags |= END_NOTE_FADE;
  65. } break;
  66. }
  67. }
  68. }
  69. if (aux_chn_ctrl->duplicate_check_type != CPInstrument::DCT_DISABLED) {
  70. int i;
  71. for (i = 0; i < control.max_voices; i++) {
  72. if (!mixer->is_voice_active(i) ||
  73. (voice[i].master_channel != aux_chn_ctrl) ||
  74. (aux_chn_ctrl->instrument_index != voice[i].instrument_index))
  75. continue;
  76. Voice_Control *aux_voc_ctrl;
  77. aux_voc_ctrl = &voice[i];
  78. k = false;
  79. switch (aux_chn_ctrl->duplicate_check_type) {
  80. case CPInstrument::DCT_NOTE:
  81. if (aux_chn_ctrl->note == aux_voc_ctrl->note)
  82. k = true;
  83. break;
  84. case CPInstrument::DCT_SAMPLE:
  85. if (aux_chn_ctrl->sample_ptr == aux_voc_ctrl->sample_ptr)
  86. k = true;
  87. break;
  88. case CPInstrument::DCT_INSTRUMENT:
  89. k = true;
  90. break;
  91. }
  92. if (k) {
  93. switch (aux_chn_ctrl->duplicate_check_action) {
  94. case CPInstrument::DCA_NOTE_CUT: {
  95. aux_voc_ctrl->fadeout_volume = 0;
  96. } break;
  97. case CPInstrument::DCA_NOTE_OFF: {
  98. aux_voc_ctrl->note_end_flags |= END_NOTE_OFF;
  99. if (!aux_voc_ctrl->volume_envelope_ctrl.active || aux_chn_ctrl->instrument_ptr->get_volume_envelope()->is_loop_enabled()) {
  100. aux_voc_ctrl->note_end_flags |= END_NOTE_FADE;
  101. }
  102. } break;
  103. case CPInstrument::DCA_NOTE_FADE: {
  104. aux_voc_ctrl->note_end_flags |= END_NOTE_FADE;
  105. } break;
  106. }
  107. }
  108. }
  109. }
  110. } /* if (aux_chn_ctrl->kick==KICK_NOTE) */
  111. }
  112. }