cp_sample.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*************************************************************************/
  2. /* cp_sample.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_sample.h"
  31. const char *CPSample::get_name() const {
  32. return name;
  33. }
  34. void CPSample::set_name(const char *p_name) {
  35. if (p_name == NULL) {
  36. name[0] = 0;
  37. return;
  38. }
  39. bool done = false;
  40. for (int i = 0; i < NAME_MAX_LEN; i++) {
  41. name[i] = done ? 0 : p_name[i];
  42. if (!done && p_name[i] == 0)
  43. done = true;
  44. }
  45. name[NAME_MAX_LEN - 1] = 0; /* just in case */
  46. }
  47. void CPSample::set_default_volume(uint8_t p_vol) {
  48. default_volume = p_vol;
  49. }
  50. uint8_t CPSample::get_default_volume() const {
  51. return default_volume;
  52. }
  53. void CPSample::set_global_volume(uint8_t p_vol) {
  54. global_volume = p_vol;
  55. }
  56. uint8_t CPSample::get_global_volume() const {
  57. return global_volume;
  58. }
  59. void CPSample::set_pan_enabled(bool p_vol) {
  60. pan_enabled = p_vol;
  61. }
  62. bool CPSample::is_pan_enabled() const {
  63. return pan_enabled;
  64. }
  65. void CPSample::set_pan(uint8_t p_pan) {
  66. pan = p_pan;
  67. }
  68. uint8_t CPSample::get_pan() const {
  69. return pan;
  70. }
  71. void CPSample::set_vibrato_type(VibratoType p_vibrato_type) {
  72. vibrato_type = p_vibrato_type;
  73. }
  74. CPSample::VibratoType CPSample::get_vibrato_type() const {
  75. return vibrato_type;
  76. }
  77. void CPSample::set_vibrato_speed(uint8_t p_vibrato_speed) {
  78. vibrato_speed = p_vibrato_speed;
  79. }
  80. uint8_t CPSample::get_vibrato_speed() const {
  81. return vibrato_speed;
  82. }
  83. void CPSample::set_vibrato_depth(uint8_t p_vibrato_depth) {
  84. vibrato_depth = p_vibrato_depth;
  85. }
  86. uint8_t CPSample::get_vibrato_depth() const {
  87. return vibrato_depth;
  88. }
  89. void CPSample::set_vibrato_rate(uint8_t p_vibrato_rate) {
  90. vibrato_rate = p_vibrato_rate;
  91. }
  92. uint8_t CPSample::get_vibrato_rate() const {
  93. return vibrato_rate;
  94. }
  95. void CPSample::set_sample_data(CPSample_ID p_ID) {
  96. id = p_ID;
  97. }
  98. CPSample_ID CPSample::get_sample_data() const {
  99. return id;
  100. }
  101. void CPSample::operator=(const CPSample &p_sample) {
  102. copy_from(p_sample);
  103. }
  104. void CPSample::copy_from(const CPSample &p_sample) {
  105. reset();
  106. set_name(p_sample.get_name());
  107. default_volume = p_sample.default_volume;
  108. global_volume = p_sample.global_volume;
  109. pan_enabled = p_sample.pan_enabled;
  110. pan = p_sample.pan;
  111. vibrato_type = p_sample.vibrato_type;
  112. vibrato_speed = p_sample.vibrato_speed;
  113. vibrato_depth = p_sample.vibrato_depth;
  114. vibrato_rate = p_sample.vibrato_rate;
  115. if (CPSampleManager::get_singleton() && !p_sample.id.is_null())
  116. CPSampleManager::get_singleton()->copy_to(p_sample.id, id);
  117. }
  118. void CPSample::reset() {
  119. name[0] = 0;
  120. default_volume = 64;
  121. global_volume = 64;
  122. pan_enabled = false;
  123. pan = 32;
  124. vibrato_type = VIBRATO_SINE;
  125. vibrato_speed = 0;
  126. vibrato_depth = 0;
  127. vibrato_rate = 0;
  128. if (!id.is_null() && CPSampleManager::get_singleton())
  129. CPSampleManager::get_singleton()->destroy(id);
  130. id = CPSample_ID();
  131. }
  132. CPSample::CPSample(const CPSample &p_from) {
  133. reset();
  134. copy_from(p_from);
  135. }
  136. CPSample::CPSample() {
  137. reset();
  138. }
  139. CPSample::~CPSample() {
  140. reset();
  141. }