LabelPosition.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 "LabelPosition.h"
  42. #include "ScorePosition.h"
  43. #include "util_log.h"
  44. #include "util_score.h"
  45. namespace sinsy
  46. {
  47. /*!
  48. constructor
  49. */
  50. LabelPosition::LabelPosition() : count(0), time(0.0), point(0), duration(0)
  51. {
  52. }
  53. /*!
  54. constructor
  55. */
  56. LabelPosition::LabelPosition(size_t dur, double tempo) : count(0), time(0.0), point(0), duration(0)
  57. {
  58. add(dur, tempo);
  59. }
  60. /*!
  61. copy constructor
  62. */
  63. LabelPosition::LabelPosition(const LabelPosition& obj) : count(obj.count), time(obj.time), point(obj.point), duration(obj.duration)
  64. {
  65. }
  66. /*!
  67. destructor
  68. */
  69. LabelPosition::~LabelPosition()
  70. {
  71. }
  72. /*!
  73. assignment operator
  74. */
  75. LabelPosition& LabelPosition::operator=(const LabelPosition & obj)
  76. {
  77. if (&obj != this) {
  78. count = obj.count;
  79. time = obj.time;
  80. point = obj.point;
  81. duration = obj.duration;
  82. }
  83. return *this;
  84. }
  85. /*!
  86. operator +=
  87. */
  88. LabelPosition& LabelPosition::operator+=(const LabelPosition & obj)
  89. {
  90. count += obj.count;
  91. time += obj.time;
  92. point += obj.point;
  93. duration += obj.duration;
  94. return *this;
  95. }
  96. /*!
  97. operator -=
  98. */
  99. LabelPosition& LabelPosition::operator-=(const LabelPosition & obj)
  100. {
  101. count -= obj.count;
  102. time -= obj.time;
  103. point -= obj.point;
  104. duration -= obj.duration;
  105. return *this;
  106. }
  107. /*!
  108. operator +
  109. */
  110. LabelPosition LabelPosition::operator+(const LabelPosition& obj) const
  111. {
  112. LabelPosition ret(*this);
  113. ret += obj;
  114. return ret;
  115. }
  116. /*!
  117. operator -
  118. */
  119. LabelPosition LabelPosition::operator-(const LabelPosition& obj) const
  120. {
  121. LabelPosition ret(*this);
  122. ret -= obj;
  123. return ret;
  124. }
  125. /*!
  126. add
  127. */
  128. void LabelPosition::add(size_t dur, double tempo)
  129. {
  130. double t(dur * 60 / (BASE_DIVISIONS * tempo));
  131. size_t p(dur * 24);
  132. ++count;
  133. time += t;
  134. point += p;
  135. duration += dur;
  136. }
  137. /*!
  138. set count
  139. */
  140. void LabelPosition::setCount(size_t c)
  141. {
  142. count = c;
  143. }
  144. /*!
  145. get count
  146. */
  147. sinsy::INT64 LabelPosition::getCount() const
  148. {
  149. return count;
  150. }
  151. /*!
  152. get time
  153. */
  154. double LabelPosition::getTime() const
  155. {
  156. return time;
  157. }
  158. /*!
  159. get point
  160. */
  161. sinsy::INT64 LabelPosition::getPoint() const
  162. {
  163. return static_cast<INT64>(point / BASE_DIVISIONS);
  164. }
  165. /*!
  166. get duration
  167. */
  168. sinsy::INT64 LabelPosition::getDuration() const
  169. {
  170. return duration;
  171. }
  172. /*!
  173. to stream
  174. */
  175. std::ostream& operator<<(std::ostream& os, const LabelPosition& obj)
  176. {
  177. os << "count:" << obj.getCount() << ", time:" << obj.getTime() << ", point:" << obj.getPoint() << ", duration:" << obj.getDuration();
  178. return os;
  179. }
  180. }; // namespace sinsy