void PowerTabOldImporter::convertGuitarIns( const PowerTabDocument::Score &oldScore, Score &score) { // For each guitar, keep track of its current staff. std::array<int, PowerTabDocument::Score::MAX_NUM_GUITARS> activePlayers; activePlayers.fill(-1); for (size_t i = 0; i < oldScore.GetSystemCount(); ++i) { std::vector<PowerTabDocument::Score::GuitarInPtr> guitarIns; oldScore.GetGuitarInsInSystem(guitarIns, oldScore.GetSystem(i)); if (guitarIns.empty()) continue; size_t currentPosition = guitarIns.front()->GetPosition(); // In v1.7, each staff has separate guitar ins. In the new format, // player changes occur at the system level so we need to combine // the guitar ins from several staves. for (auto &guitarIn : guitarIns) { // For now, ignore guitar ins that only affect rhythm slashes. if (!guitarIn->HasStaffGuitarsSet()) continue; // After combining all guitar in's at a position, write out a player // change. if (guitarIn->GetPosition() != currentPosition) { score.getSystems()[i].insertPlayerChange(getPlayerChange( activePlayers, static_cast<int>(currentPosition))); } // Clear out any players that are currently active for this staff. const int staff = guitarIn->GetStaff(); for (auto &activePlayer : activePlayers) { if (activePlayer == staff) activePlayer = -1; } // Set the active players for this staff. std::bitset<8> activeGuitars(guitarIn->GetStaffGuitars()); for (size_t k = 0; k < activePlayers.size(); ++k) { if (activeGuitars[k]) activePlayers[k] = staff; } currentPosition = guitarIn->GetPosition(); } // After processing all of the guitar ins in the system, write out a // final player change. score.getSystems()[i].insertPlayerChange( getPlayerChange(activePlayers, static_cast<int>(currentPosition))); } }
void PowerTabOldImporter::convertFloatingText( const PowerTabDocument::Score &oldScore, Score &score) { for (size_t i = 0, n = oldScore.GetFloatingTextCount(); i < n; ++i) { // Convert from an absolute (x,y) position to a (system,position) // location. auto floatingText = oldScore.GetFloatingText(i); PowerTabDocument::Rect location = floatingText->GetRect(); // Figure out which system to attach to. size_t attachedSystemIdx = oldScore.GetSystemCount() - 1; for (size_t j = 0, n = oldScore.GetSystemCount(); j < n; ++j) { auto system = oldScore.GetSystem(j); if (system->GetRect().GetBottom() > location.GetTop()) { attachedSystemIdx = j; break; } } // Figure out what position in the system to use. auto system = oldScore.GetSystem(attachedSystemIdx); const int position = static_cast<int>(system->GetPositionFromX(location.GetX())); // Create the text item in the new score. TextItem item(position, floatingText->GetText()); score.getSystems()[attachedSystemIdx].insertTextItem(item); } }
RemoveSystem::RemoveSystem(Score &score, int index, Caret &caret) : QUndoCommand(QObject::tr("Remove System")), myScore(score), myIndex(index), myCaret(caret), myOriginalSystem(score.getSystems()[index]) { }
void PowerTabOldImporter::convertInitialVolumes( const PowerTabDocument::Score &oldScore, Score &score) { if (oldScore.GetGuitarInCount() > 0) { auto firstIn = oldScore.GetGuitarIn(0); const SystemLocation startPos(firstIn->GetSystem(), firstIn->GetPosition()); System &system = score.getSystems()[firstIn->GetSystem()]; // If there was a dynamic at or before the first guitar in, then that // dynamic is used. if (oldScore.GetDynamicCount() > 0) { auto firstDynamic = oldScore.GetDynamic(0); if (SystemLocation(firstDynamic->GetSystem(), firstDynamic->GetPosition()) <= startPos) { return; } } for (size_t i = 0; i < oldScore.GetGuitarInCount(); ++i) { // Import guitar ins from every staff at the first location. auto guitarIn = oldScore.GetGuitarIn(i); const SystemLocation pos(guitarIn->GetSystem(), guitarIn->GetPosition()); if (pos != startPos) continue; else if (!guitarIn->HasStaffGuitarsSet()) continue; std::bitset<8> activeGuitars(guitarIn->GetStaffGuitars()); for (size_t j = 0; j < oldScore.GetGuitarCount(); ++j) { if (activeGuitars[j]) { Dynamic dynamic( guitarIn->GetPosition(), static_cast<Dynamic::VolumeLevel>( oldScore.GetGuitar(j)->GetInitialVolume())); system.getStaves()[guitarIn->GetStaff()].insertDynamic(dynamic); break; } } } } }
void EditStaff::addPlayerChangeAtStart(Score &score, int system_index) { System &system = score.getSystems()[system_index]; const PlayerChange *current_players = ScoreUtils::getCurrentPlayers(score, system_index, 0); if (current_players && (system.getPlayerChanges().empty() || system.getPlayerChanges().front().getPosition() != 0)) { PlayerChange change(*current_players); change.setPosition(0); system.insertPlayerChange(change); } }
GoToBarlineDialog::GoToBarlineDialog(QWidget *parent, const Score &score) : QDialog(parent), ui(new Ui::GoToBarlineDialog) { ui->setupUi(this); for (int system_index = 0; system_index < score.getSystems().size(); ++system_index) { const System &system = score.getSystems()[system_index]; // Index all barlines except for the end bar. for (int i = 0; i < system.getBarlines().size() - 1; ++i) { myLocations.push_back(ScoreLocation( score, system_index, 0, system.getBarlines()[i].getPosition())); } } ui->barlineSpinBox->setValue(1); ui->barlineSpinBox->setMinimum(1); ui->barlineSpinBox->setMaximum(static_cast<int>(myLocations.size())); ui->barlineSpinBox->selectAll(); }
* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <catch.hpp> #include <actions/removesystem.h> #include <app/caret.h> #include <score/score.h> TEST_CASE("Actions/RemoveSystem", "") { Score score; System system; score.insertSystem(system); score.insertSystem(system); RemoveSystem action(score, 1); action.redo(); REQUIRE(score.getSystems().size() == 1); action.undo(); REQUIRE(score.getSystems().size() == 2); }
* GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <catch.hpp> #include <actions/removeplayerchange.h> #include <score/score.h> #include <score/scorelocation.h> TEST_CASE("Actions/RemovePlayerChange", "") { Score score; System system; PlayerChange change(5); change.insertActivePlayer(1, ActivePlayer(0, 2)); system.insertPlayerChange(change); score.insertSystem(system); RemovePlayerChange action(ScoreLocation(score, 0, 0, 5)); action.redo(); REQUIRE(score.getSystems()[0].getPlayerChanges().size() == 0); action.undo(); REQUIRE(score.getSystems()[0].getPlayerChanges().size() == 1); REQUIRE(score.getSystems()[0].getPlayerChanges()[0] == change); }
* it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <catch.hpp> #include <app/appinfo.h> #include <formats/gpx/gpximporter.h> #include <score/score.h> TEST_CASE("Formats/GpxImport/Text", "") { Score score; GpxImporter importer; importer.load(AppInfo::getAbsolutePath("data/text.gpx"), score); const System &system = score.getSystems()[0]; REQUIRE(system.getTextItems().size() == 1); REQUIRE(system.getTextItems()[0].getPosition() == 9); REQUIRE(system.getTextItems()[0].getContents() == "foo"); }