Rosegarden – music editor and MIDI/audio sequencer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.9KB

  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-2007
  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 "SegmentSyncCommand.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. #include "commands/segment/SegmentTransposeCommand.h"
  25. #include "commands/segment/SegmentSyncClefCommand.h"
  26. namespace Rosegarden
  27. {
  28. SegmentSyncCommand::SegmentSyncCommand(Segment &segment, int newTranspose, int lowRange, int highRange, const Clef& clef) :
  29. KMacroCommand(i18n("Sync segment parameters"))
  30. {
  31. processSegment(segment, newTranspose, lowRange, highRange, clef);
  32. }
  33. SegmentSyncCommand::SegmentSyncCommand(SegmentSelection selection, int newTranspose, int lowRange, int highRange, const Clef& clef) :
  34. KMacroCommand(i18n("Sync segment parameters"))
  35. {
  36. for (SegmentSelection::iterator i = selection.begin();
  37. i != selection.end(); ++i)
  38. {
  39. Segment &segment = **i;
  40. processSegment(segment, newTranspose, lowRange, highRange, clef);
  41. }
  42. }
  43. SegmentSyncCommand::SegmentSyncCommand(std::vector<Segment *> segments, int newTranspose, int lowRange, int highRange, const Clef& clef) :
  44. KMacroCommand(i18n("Sync segment parameters"))
  45. {
  46. for (int i = 0; i < segments.size(); i++) {
  47. processSegment(*(segments[i]), newTranspose, lowRange, highRange, clef);
  48. }
  49. }
  50. SegmentSyncCommand::SegmentSyncCommand(Composition::segmentcontainer& segments, TrackId selectedTrack, int newTranspose, int lowRange, int highRange, const Clef& clef) :
  51. KMacroCommand(i18n("Sync segment parameters"))
  52. {
  53. for (Composition::segmentcontainer::const_iterator si = segments.begin();
  54. si != segments.end(); ++si) {
  55. if ((*si)->getTrack() == selectedTrack) {
  56. processSegment(**si, newTranspose, lowRange, highRange, clef);
  57. }
  58. }
  59. }
  60. void
  61. SegmentSyncCommand::processSegment(Segment &segment, int newTranspose, int lowRange, int highRange, const Clef& clef)
  62. {
  63. KMacroCommand * macroCommand = this;
  64. // if the new desired setting for 'transpose' is higher, we need to
  65. // transpose the notes upwards to compensate:
  66. int semitones = segment.getTranspose() - newTranspose;
  67. // Say the old transpose was -2 and the new is 0, this corresponds to
  68. // Bb and C. The height of the old transpose is 1 below the height of the new.
  69. int oldHeight = Pitch(segment.getTranspose()).getHeightOnStaff(Clef::Treble, Key("C major"));
  70. int newHeight = Pitch(newTranspose).getHeightOnStaff(Clef::Treble, Key("C major"));
  71. int steps = oldHeight - newHeight;
  72. SegmentTransposeCommand* command = new SegmentTransposeCommand(segment, true, steps, semitones, true);
  73. macroCommand->addCommand(command);
  74. // TODO do this in an undoable fashion:
  75. segment.setLowestPlayable(lowRange);
  76. segment.setHighestPlayable(highRange);
  77. macroCommand->addCommand(new SegmentSyncClefCommand(segment, clef));
  78. }
  79. SegmentSyncCommand::~SegmentSyncCommand()
  80. {}
  81. }