Rosegarden – music editor and MIDI/audio sequencer
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

124 satır
4.5KB

  1. /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
  2. /*
  3. Rosegarden
  4. A MIDI and audio sequencer and musical notation editor.
  5. This program is Copyright 2000-2008
  6. Guillaume Laurent <glaurent@telegraph-road.org>,
  7. Chris Cannam <cannam@all-day-breakfast.com>,
  8. Richard Bown <richard.bown@ferventsoftware.com>
  9. The moral rights of Guillaume Laurent, Chris Cannam, and Richard
  10. Bown to claim authorship of this work have been asserted.
  11. Other copyrights also apply to some parts of this work. Please
  12. see the AUTHORS file and individual file headers for details.
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License as
  15. published by the Free Software Foundation; either version 2 of the
  16. License, or (at your option) any later version. See the file
  17. COPYING included with this distribution for more information.
  18. */
  19. #include "SegmentTransposeCommand.h"
  20. #include "base/Selection.h"
  21. #include "commands/notation/KeyInsertionCommand.h"
  22. #include "commands/edit/TransposeCommand.h"
  23. #include "commands/segment/SegmentChangeTransposeCommand.h"
  24. namespace Rosegarden
  25. {
  26. SegmentTransposeCommand::SegmentTransposeCommand(Segment &segment, bool changeKey, int steps, int semitones, bool transposeSegmentBack) :
  27. KMacroCommand(i18n("Change segment transposition"))
  28. {
  29. processSegment(segment, changeKey, steps, semitones, transposeSegmentBack);
  30. }
  31. SegmentTransposeCommand::SegmentTransposeCommand(SegmentSelection selection, bool changeKey, int steps, int semitones, bool transposeSegmentBack) :
  32. KMacroCommand(i18n("Change segment transposition"))
  33. {
  34. //SegmentSelection selection(m_view->getSelection());
  35. for (SegmentSelection::iterator i = selection.begin();
  36. i != selection.end(); ++i)
  37. {
  38. Segment &segment = **i;
  39. processSegment(segment, changeKey, steps, semitones, transposeSegmentBack);
  40. }
  41. }
  42. void
  43. SegmentTransposeCommand::processSegment(Segment &segment, bool changeKey, int steps, int semitones, bool transposeSegmentBack)
  44. {
  45. KMacroCommand * macroCommand = this;
  46. // TODO delete it somewhere.
  47. EventSelection * wholeSegment = new EventSelection(segment, segment.getStartTime(), segment.getEndMarkerTime());
  48. macroCommand->addCommand(new TransposeCommand
  49. (semitones, steps, *wholeSegment));
  50. // Key insertion can do transposition, but a C4 to D becomes a D4, while
  51. // a C4 to G becomes a G3. Because we let the user specify an explicit number
  52. // of octaves to move the notes up/down, we add the keys without transposing
  53. // and handle the transposition seperately:
  54. if (changeKey)
  55. {
  56. Rosegarden::Key initialKey = segment.getKeyAtTime(segment.getStartTime());
  57. Rosegarden::Key newInitialKey = initialKey.transpose(semitones, steps);
  58. EventSelection::eventcontainer::iterator i;
  59. //std::list<KeyInsertionCommand*> commands;
  60. for (i = wholeSegment->getSegmentEvents().begin();
  61. i != wholeSegment->getSegmentEvents().end(); ++i) {
  62. // transpose key
  63. if ((*i)->isa(Rosegarden::Key::EventType)) {
  64. Rosegarden::Key trKey = (Rosegarden::Key (**i)).transpose(semitones, steps);
  65. //commands.push_front
  66. macroCommand->addCommand
  67. (new KeyInsertionCommand
  68. (segment,
  69. (*i)->getAbsoluteTime(),
  70. trKey,
  71. false,
  72. false,
  73. false,
  74. true));
  75. }
  76. }
  77. std::list<KeyInsertionCommand*>::iterator ci;
  78. //for (ci=commands.begin(); ci!=commands.end(); ci++)
  79. //{
  80. // commandHistory->addCommand(*ci);
  81. //}
  82. KeyInsertionCommand *firstKeyCommand = new KeyInsertionCommand
  83. (segment,
  84. segment.getStartTime(),
  85. newInitialKey,
  86. false,
  87. false,
  88. false,
  89. true);
  90. //commandHistory->addCommand(firstKeyCommand);
  91. macroCommand->addCommand(firstKeyCommand);
  92. }
  93. if (transposeSegmentBack)
  94. {
  95. // Transpose segment in opposite direction
  96. int newTranspose = segment.getTranspose() - semitones;
  97. macroCommand->addCommand(new SegmentChangeTransposeCommand(newTranspose, &segment));
  98. }
  99. }
  100. SegmentTransposeCommand::~SegmentTransposeCommand()
  101. {}
  102. }