NoteLabeler.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. #ifndef SINSY_NOTE_LABELER_H_
  42. #define SINSY_NOTE_LABELER_H_
  43. #include <vector>
  44. #include "Pitch.h"
  45. #include "Beat.h"
  46. #include "Key.h"
  47. #include "Syllabic.h"
  48. #include "Dynamics.h"
  49. #include "Note.h"
  50. #include "IConvertable.h"
  51. #include "LabelPosition.h"
  52. #include "SyllableLabeler.h"
  53. #include "NoteGroup.h"
  54. #include "LabelMeasure.h"
  55. #include "INoteLabel.h"
  56. #include "PhonemeInfo.h"
  57. #include "util_converter.h"
  58. namespace sinsy
  59. {
  60. class NoteLabeler : public IConvertable
  61. {
  62. public:
  63. typedef std::vector<SyllableLabeler*> List;
  64. //! constructor
  65. NoteLabeler(const Beat& b, const Dynamics& d, const Key& k);
  66. //! destructor
  67. virtual ~NoteLabeler();
  68. //! is rest or not
  69. virtual bool isRest() const;
  70. //! already converted or not
  71. virtual bool isConverted() const;
  72. //! get lyric
  73. virtual std::string getLyric() const;
  74. //! get syllabic
  75. virtual Syllabic getSyllabic() const;
  76. //! get duration
  77. size_t getDuration() const;
  78. //! add information
  79. virtual void addInfo(const std::vector<PhonemeInfo>& phonemes, const std::string& language, const std::string& info);
  80. //! set label
  81. virtual void setLabel(INoteLabel& label) const;
  82. //! add note
  83. void addNote(const Note& note, double tempo);
  84. //! get beat
  85. const Beat& getBeat() const;
  86. //! get dynamics
  87. const Dynamics& getDynamics() const;
  88. //! get key
  89. const Key& getKey() const;
  90. //! set measure
  91. void setMeasure(LabelMeasure* m);
  92. //! set phrase
  93. void setPhrase(NoteGroup* ng);
  94. //! set crescendo
  95. void setCrescendo(NoteGroup* ng);
  96. //! set diminuendo
  97. void setDiminuendo(NoteGroup* ng);
  98. //! set prev phrase
  99. void setPrevPhrase(const NoteGroup* ng);
  100. //! set next phrase
  101. void setNextPhrase(const NoteGroup* ng);
  102. //! get phrase
  103. const NoteGroup* getPhrase() const;
  104. //! get pitch
  105. Pitch getPitch() const;
  106. //! set positions
  107. void setPositions();
  108. //! is slur start or not
  109. bool isSlurStart() const;
  110. //! is slur stop or not
  111. bool isSlurStop() const;
  112. //! set if this note is in slur from previous note or not
  113. void setInSlurFromPrev(bool b);
  114. //! set if this note is in slur to next note or not
  115. void setInSlurToNext(bool b);
  116. //! set previous pitch
  117. void setPrevPitch(const Pitch& p);
  118. //! set next pitch
  119. void setNextPitch(const Pitch& p);
  120. //! get length
  121. LabelPosition getLength() const;
  122. //! set next accent position
  123. void setNextAccentPosition(const LabelPosition& p);
  124. //! set previous accent position
  125. void setPrevAccentPosition(const LabelPosition& p);
  126. //! set next staccato position
  127. void setNextStaccatoPosition(const LabelPosition& p);
  128. //! set previous staccato position
  129. void setPrevStaccatoPosition(const LabelPosition& p);
  130. //! get number of syllables
  131. size_t getSyllableNum() const;
  132. //! has accent or not
  133. bool hasAccent() const;
  134. //! has staccato or not
  135. bool hasStaccato() const;
  136. //! if this note has breath between this and next node, return true.
  137. bool hasBreathToNext() const;
  138. //! set previous note (null -> this is the head note)
  139. void setPrevNote(const NoteLabeler* prev);
  140. //! set next note (null -> this is the tail note)
  141. void setNextNote(const NoteLabeler* next);
  142. //! ...
  143. const LabelPosition& getMeasureIdx() const;
  144. //! ...
  145. void moveTo(NoteLabeler&, size_t = 0);
  146. //! set breath phoneme to the tail of the last syllable
  147. void setBreathPhoneme();
  148. //! get begin iteration
  149. List::const_iterator childBegin() const;
  150. //! get end iteration
  151. List::const_iterator childEnd() const;
  152. private:
  153. //! copy constructor (donot use)
  154. NoteLabeler(const NoteLabeler&);
  155. //! assignment operator (donot use)
  156. NoteLabeler& operator=(const NoteLabeler&);
  157. //! connect lyrics
  158. std::string connectLyrics();
  159. //! list of children
  160. List children;
  161. //! previous note
  162. const NoteLabeler* prevNote;
  163. //! next note
  164. const NoteLabeler* nextNote;
  165. class NoteData
  166. {
  167. public:
  168. //! constructor
  169. NoteData(const Note& n, double t);
  170. //! destructor
  171. virtual ~NoteData();
  172. //! get note
  173. const Note& getNote() const;
  174. //! get tempo
  175. double getTempo() const;
  176. //! get length
  177. LabelPosition getLength() const;
  178. private:
  179. //! copy constructor (donot use)
  180. NoteData(const NoteData&);
  181. //! assignment operator (donot use)
  182. NoteData& operator=(const NoteData&);
  183. //! note
  184. Note note;
  185. //! tempo
  186. double tempo;
  187. friend class NoteLabeler;
  188. };
  189. class PositionAdder
  190. {
  191. public:
  192. //! constructor
  193. explicit PositionAdder(LabelPosition& p);
  194. //! copy constructor
  195. PositionAdder(const PositionAdder& obj);
  196. //! destructor
  197. virtual ~PositionAdder();
  198. //! ...
  199. void operator()(NoteData* data);
  200. private:
  201. //! assignment operator (donot use)
  202. PositionAdder& operator=(const PositionAdder&);
  203. //! position
  204. LabelPosition& position;
  205. };
  206. //! lyric
  207. std::string lyric;
  208. //! beat
  209. const Beat beat;
  210. //! dynamics
  211. const Dynamics dynamics;
  212. //! key
  213. const Key key;
  214. //! in slur from previous note or not
  215. bool inSlurFromPrev;
  216. //! in slur to next note or not
  217. bool inSlurToNext;
  218. //! pitch difference from previous note
  219. int pitchDifferenceFromPrev;
  220. //! pitch difference to next note
  221. int pitchDifferenceToNext;
  222. //! has prevois pitch or not
  223. bool hasPrevPitch;
  224. //! has next pitch or not
  225. bool hasNextPitch;
  226. //! previous accent
  227. LabelPosition prevAccent;
  228. //! next accent
  229. LabelPosition nextAccent;
  230. //! previous staccato
  231. LabelPosition prevStaccato;
  232. //! next staccato
  233. LabelPosition nextStaccato;
  234. //! measure
  235. LabelMeasure* measure;
  236. //! phrase
  237. NoteGroup* phrase;
  238. //! crescendo
  239. const NoteGroup* crescendo;
  240. //! diminuendo
  241. const NoteGroup* diminuendo;
  242. //! previous phrase
  243. const NoteGroup* prevPhrase;
  244. //! next phrase
  245. const NoteGroup* nextPhrase;
  246. //! meausre index
  247. LabelPosition measureIdx;
  248. //! phrase index
  249. LabelPosition phraseIdx;
  250. //! crescendo index
  251. LabelPosition crescendoIdx;
  252. //! diminuendo index
  253. LabelPosition diminuendoIdx;
  254. typedef std::vector<NoteData*> DataList;
  255. //! data list
  256. DataList dataList;
  257. };
  258. };
  259. #endif // SINSY_NOTE_LABELER_H_