TempScore.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 "TempScore.h"
  43. #include "util_score.h"
  44. #include "Deleter.h"
  45. namespace sinsy
  46. {
  47. /*!
  48. constructor
  49. */
  50. TempScore::TempScore()
  51. {}
  52. /*!
  53. destructor
  54. */
  55. TempScore::~TempScore()
  56. {
  57. clear();
  58. }
  59. /*!
  60. clear
  61. */
  62. void TempScore::clear()
  63. {
  64. std::for_each(tempList.begin(), tempList.end(), Deleter<ITempData>());
  65. tempList.clear();
  66. }
  67. /*!
  68. write
  69. */
  70. void TempScore::write(IScoreWritable& sm) const
  71. {
  72. std::for_each(tempList.begin(), tempList.end(), DataSetter(sm));
  73. }
  74. /*!
  75. set encoding
  76. */
  77. void TempScore::setEncoding(const std::string& e)
  78. {
  79. tempList.push_back(new EncodingSetter(e));
  80. }
  81. /*!
  82. change tempo
  83. */
  84. void TempScore::changeTempo(double d)
  85. {
  86. tempList.push_back(new TempoChanger(d));
  87. }
  88. /*!
  89. change beat
  90. */
  91. void TempScore::changeBeat(const Beat& b)
  92. {
  93. tempList.push_back(new BeatChanger(b));
  94. }
  95. /*!
  96. change dynamics
  97. */
  98. void TempScore::changeDynamics(const Dynamics& d)
  99. {
  100. tempList.push_back(new DynamicsChanger(d));
  101. }
  102. /*!
  103. change key
  104. */
  105. void TempScore::changeKey(const Key& k)
  106. {
  107. tempList.push_back(new KeyChanger(k));
  108. }
  109. /*!
  110. start crescendo
  111. */
  112. void TempScore::startCrescendo()
  113. {
  114. tempList.push_back(new CrescendoStarter());
  115. }
  116. /*!
  117. start diminuendo
  118. */
  119. void TempScore::startDiminuendo()
  120. {
  121. tempList.push_back(new DiminuendoStarter());
  122. }
  123. /*!
  124. stop crescendo
  125. */
  126. void TempScore::stopCrescendo()
  127. {
  128. tempList.push_back(new CrescendoStopper());
  129. }
  130. /*!
  131. stop diminuendo
  132. */
  133. void TempScore::stopDiminuendo()
  134. {
  135. tempList.push_back(new DiminuendoStopper());
  136. }
  137. /*!
  138. add note
  139. */
  140. void TempScore::addNote(const Note& n)
  141. {
  142. tempList.push_back(new NoteAdder(n));
  143. }
  144. /*!
  145. constructor
  146. */
  147. TempScore::EncodingSetter::EncodingSetter(const std::string& e) : encoding(e)
  148. {
  149. }
  150. /*!
  151. destructor
  152. */
  153. TempScore::EncodingSetter::~EncodingSetter()
  154. {
  155. }
  156. /*!
  157. write
  158. */
  159. void TempScore::EncodingSetter::write(IScoreWritable& sm) const
  160. {
  161. sm.setEncoding(encoding);
  162. }
  163. /*!
  164. constructor
  165. */
  166. TempScore::NoteAdder::NoteAdder(const Note& n) : note(n)
  167. {
  168. }
  169. /*!
  170. destructor
  171. */
  172. TempScore::NoteAdder::~NoteAdder()
  173. {
  174. }
  175. /*!
  176. write
  177. */
  178. void TempScore::NoteAdder::write(IScoreWritable& sm) const
  179. {
  180. sm.addNote(note);
  181. }
  182. //! get note
  183. const Note& TempScore::NoteAdder::getNote() const
  184. {
  185. return note;
  186. }
  187. //! get note
  188. Note& TempScore::NoteAdder::getNote()
  189. {
  190. return note;
  191. }
  192. /*!
  193. constructor
  194. */
  195. TempScore::TempoChanger::TempoChanger(double t) : tempo(t)
  196. {
  197. }
  198. /*!
  199. destructor
  200. */
  201. TempScore::TempoChanger::~TempoChanger()
  202. {
  203. }
  204. /*!
  205. write
  206. */
  207. void TempScore::TempoChanger::write(IScoreWritable& sm) const
  208. {
  209. sm.changeTempo(tempo);
  210. }
  211. /*!
  212. constructor
  213. */
  214. TempScore::BeatChanger::BeatChanger(const Beat& b) : beat(b)
  215. {
  216. }
  217. /*!
  218. destructor
  219. */
  220. TempScore::BeatChanger::~BeatChanger()
  221. {
  222. }
  223. /*!
  224. write
  225. */
  226. void TempScore::BeatChanger::write(IScoreWritable& sm) const
  227. {
  228. sm.changeBeat(beat);
  229. }
  230. /*!
  231. constructor
  232. */
  233. TempScore::DynamicsChanger::DynamicsChanger(const Dynamics& d) : dynamics(d)
  234. {
  235. }
  236. /*!
  237. destructor
  238. */
  239. TempScore::DynamicsChanger::~DynamicsChanger()
  240. {
  241. }
  242. /*!
  243. write
  244. */
  245. void TempScore::DynamicsChanger::write(IScoreWritable& sm) const
  246. {
  247. sm.changeDynamics(dynamics);
  248. }
  249. /*!
  250. constructor
  251. */
  252. TempScore::KeyChanger::KeyChanger(const Key& k) : key(k)
  253. {}
  254. /*!
  255. destructor
  256. */
  257. TempScore::KeyChanger::~KeyChanger()
  258. {
  259. }
  260. /*!
  261. write
  262. */
  263. void TempScore::KeyChanger::write(IScoreWritable& sm) const
  264. {
  265. sm.changeKey(key);
  266. }
  267. /*!
  268. constructor
  269. */
  270. TempScore::CrescendoStarter::CrescendoStarter()
  271. {
  272. }
  273. /*!
  274. destructor
  275. */
  276. TempScore::CrescendoStarter::~CrescendoStarter()
  277. {
  278. }
  279. /*!
  280. write
  281. */
  282. void TempScore::CrescendoStarter::write(IScoreWritable& sm) const
  283. {
  284. sm.startCrescendo();
  285. }
  286. /*!
  287. constructor
  288. */
  289. TempScore::CrescendoStopper::CrescendoStopper()
  290. {
  291. }
  292. /*!
  293. destructor
  294. */
  295. TempScore::CrescendoStopper::~CrescendoStopper()
  296. {
  297. }
  298. /*!
  299. write
  300. */
  301. void TempScore::CrescendoStopper::write(IScoreWritable& sm) const
  302. {
  303. sm.stopCrescendo();
  304. }
  305. /*!
  306. constructor
  307. */
  308. TempScore::DiminuendoStarter::DiminuendoStarter()
  309. {
  310. }
  311. /*!
  312. destructor
  313. */
  314. TempScore::DiminuendoStarter::~DiminuendoStarter()
  315. {
  316. }
  317. /*!
  318. write
  319. */
  320. void TempScore::DiminuendoStarter::write(IScoreWritable& sm) const
  321. {
  322. sm.startDiminuendo();
  323. }
  324. /*!
  325. constructor
  326. */
  327. TempScore::DiminuendoStopper::DiminuendoStopper()
  328. {
  329. }
  330. /*!
  331. destructor
  332. */
  333. TempScore::DiminuendoStopper::~DiminuendoStopper()
  334. {
  335. }
  336. /*!
  337. write
  338. */
  339. void TempScore::DiminuendoStopper::write(IScoreWritable& sm) const
  340. {
  341. sm.stopDiminuendo();
  342. }
  343. /*!
  344. constructor
  345. */
  346. TempScore::DataSetter::DataSetter(IScoreWritable& sm) : maker(sm)
  347. {
  348. }
  349. /*!
  350. destructor
  351. */
  352. TempScore::DataSetter::~DataSetter()
  353. {
  354. }
  355. /*!
  356. ...
  357. */
  358. void TempScore::DataSetter::operator()(const ITempData* data)
  359. {
  360. maker << *data;
  361. }
  362. }; // namespace sinsy