Slur.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* ----------------------------------------------------------------- */
  2. /* The HMM-Based Singing Voice Synthesis System "Sinsy" */
  3. /* developed by Sinsy Working Group */
  4. /* http://sinsy.sourceforge.net/ */
  5. /* ----------------------------------------------------------------- */
  6. /* */
  7. /* Copyright (c) 2009-2015 Nagoya Institute of Technology */
  8. /* Department of Computer Science */
  9. /* */
  10. /* All rights reserved. */
  11. /* */
  12. /* Redistribution and use in source and binary forms, with or */
  13. /* without modification, are permitted provided that the following */
  14. /* conditions are met: */
  15. /* */
  16. /* - Redistributions of source code must retain the above copyright */
  17. /* notice, this list of conditions and the following disclaimer. */
  18. /* - Redistributions in binary form must reproduce the above */
  19. /* copyright notice, this list of conditions and the following */
  20. /* disclaimer in the documentation and/or other materials provided */
  21. /* with the distribution. */
  22. /* - Neither the name of the Sinsy working group nor the names of */
  23. /* its contributors may be used to endorse or promote products */
  24. /* derived from this software without specific prior written */
  25. /* permission. */
  26. /* */
  27. /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
  28. /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  29. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  30. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  31. /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
  32. /* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
  33. /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
  34. /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
  35. /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
  36. /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
  37. /* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
  38. /* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  39. /* POSSIBILITY OF SUCH DAMAGE. */
  40. /* ----------------------------------------------------------------- */
  41. #include <algorithm>
  42. #include "util_log.h"
  43. #include "Slur.h"
  44. namespace sinsy
  45. {
  46. /*!
  47. constructor
  48. */
  49. Slur::Slur()
  50. {
  51. }
  52. /*!
  53. copy constructor
  54. */
  55. Slur::Slur(const Slur& obj)
  56. {
  57. *this = obj;
  58. }
  59. /*!
  60. destructor
  61. */
  62. Slur::~Slur()
  63. {
  64. }
  65. /*!
  66. assignment operator
  67. */
  68. Slur& Slur::operator=(const Slur & obj)
  69. {
  70. if (this != &obj) {
  71. this->startNumberList = obj.startNumberList;
  72. this->stopNumberList = obj.stopNumberList;
  73. }
  74. return *this;
  75. }
  76. /*!
  77. add start
  78. */
  79. void Slur::addStart(int number)
  80. {
  81. NumberList::iterator itr(std::find(startNumberList.begin(), startNumberList.end(), number));
  82. if (startNumberList.end() == itr) {
  83. startNumberList.push_back(number);
  84. }
  85. }
  86. /*!
  87. @internal
  88. remove from start number list
  89. @param number target slur number
  90. @return whether the number was contained in start number list or not
  91. */
  92. bool Slur::removeFromStartNumberList(int number)
  93. {
  94. NumberList::iterator itr(std::find(startNumberList.begin(), startNumberList.end(), number));
  95. if (startNumberList.end() == itr) { // not contained in start number list
  96. return false;
  97. }
  98. startNumberList.erase(itr);
  99. return true;
  100. }
  101. /*!
  102. add stop
  103. */
  104. void Slur::addStop(int number)
  105. {
  106. bool exist(removeFromStartNumberList(number));
  107. NumberList::iterator itr(std::find(stopNumberList.begin(), stopNumberList.end(), number));
  108. if (!exist && (stopNumberList.end() == itr)) {
  109. stopNumberList.push_back(number);
  110. } else if (exist && (stopNumberList.end() != itr)) {
  111. stopNumberList.erase(itr);
  112. }
  113. }
  114. /*!
  115. no slur or not
  116. */
  117. bool Slur::noSlur() const
  118. {
  119. if (startNumberList.empty() && stopNumberList.empty()) {
  120. return true;
  121. }
  122. return false;
  123. }
  124. /*!
  125. merge to another slur
  126. */
  127. void Slur::mergeTo(Slur& slur) const
  128. {
  129. {
  130. const NumberList::const_iterator itrEnd(this->stopNumberList.end());
  131. for (NumberList::const_iterator itr(this->stopNumberList.begin()); itrEnd != itr; ++itr) {
  132. slur.addStop(*itr);
  133. }
  134. }
  135. {
  136. const NumberList::const_iterator itrEnd(this->startNumberList.end());
  137. for (NumberList::const_iterator itr(this->startNumberList.begin()); itrEnd != itr; ++itr) {
  138. slur.addStart(*itr);
  139. }
  140. }
  141. }
  142. /*!
  143. clear
  144. */
  145. void Slur::clear()
  146. {
  147. startNumberList.clear();
  148. stopNumberList.clear();
  149. }
  150. /*!
  151. to stream
  152. */
  153. std::ostream& operator<<(std::ostream& os, const Slur& slur)
  154. {
  155. {
  156. os << "Start: ";
  157. const Slur::NumberList::const_iterator itrEnd(slur.startNumberList.end());
  158. for (Slur::NumberList::const_iterator itr(slur.startNumberList.begin()); itrEnd != itr; ++itr) {
  159. if (slur.startNumberList.begin() != itr) {
  160. os << ", ";
  161. }
  162. os << (*itr);
  163. }
  164. }
  165. os << ", ";
  166. {
  167. os << "Stop: ";
  168. const Slur::NumberList::const_iterator itrEnd(slur.stopNumberList.end());
  169. for (Slur::NumberList::const_iterator itr(slur.stopNumberList.begin()); itrEnd != itr; ++itr) {
  170. if (slur.stopNumberList.begin() != itr) {
  171. os << ", ";
  172. }
  173. os << (*itr);
  174. }
  175. }
  176. return os;
  177. }
  178. }; // namespace sinsy