cp_player_data_envelopes.cpp 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*************************************************************************/
  2. /* cp_player_data_envelopes.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::Voice_Control::start_envelope(CPEnvelope *p_envelope, Envelope_Control *p_envelope_ctrl, Envelope_Control *p_from_env) {
  32. if (p_from_env && p_envelope->is_carry_enabled() && !p_from_env->terminated) {
  33. *p_envelope_ctrl = *p_from_env;
  34. } else {
  35. p_envelope_ctrl->pos_index = 0;
  36. p_envelope_ctrl->status = 1;
  37. p_envelope_ctrl->sustain_looping = p_envelope->is_sustain_loop_enabled();
  38. p_envelope_ctrl->looping = p_envelope->is_loop_enabled();
  39. p_envelope_ctrl->terminated = false;
  40. p_envelope_ctrl->kill = false;
  41. p_envelope_ctrl->value = p_envelope->get_height_at_pos(p_envelope_ctrl->pos_index);
  42. }
  43. }
  44. bool CPPlayer::Voice_Control::process_envelope(CPEnvelope *p_envelope, Envelope_Control *p_envelope_ctrl) {
  45. if (!p_envelope_ctrl->active)
  46. return false;
  47. if (note_end_flags & END_NOTE_OFF) p_envelope_ctrl->sustain_looping = false;
  48. p_envelope_ctrl->value = p_envelope->get_height_at_pos(p_envelope_ctrl->pos_index);
  49. if (p_envelope_ctrl->value == CPEnvelope::NO_POINT)
  50. return false;
  51. p_envelope_ctrl->pos_index++;
  52. if (p_envelope_ctrl->sustain_looping) {
  53. if (p_envelope_ctrl->pos_index > p_envelope->get_node(p_envelope->get_sustain_loop_end()).tick_offset) {
  54. p_envelope_ctrl->pos_index = p_envelope->get_node(p_envelope->get_sustain_loop_begin()).tick_offset;
  55. }
  56. } else if (p_envelope_ctrl->looping) {
  57. if (p_envelope_ctrl->pos_index > p_envelope->get_node(p_envelope->get_loop_end()).tick_offset) {
  58. p_envelope_ctrl->pos_index = p_envelope->get_node(p_envelope->get_loop_begin()).tick_offset;
  59. }
  60. }
  61. if (p_envelope_ctrl->pos_index > p_envelope->get_node(p_envelope->get_node_count() - 1).tick_offset) {
  62. p_envelope_ctrl->terminated = true;
  63. p_envelope_ctrl->pos_index = p_envelope->get_node(p_envelope->get_node_count() - 1).tick_offset;
  64. if (p_envelope->get_node(p_envelope->get_node_count() - 1).value == 0) p_envelope_ctrl->kill = true;
  65. }
  66. return true;
  67. }