/// Tests Serialization /// @return True if all tests were executed, false if not bool KeySignatureTestSuite::TestCaseSerialize() { //------Last Checked------// // - Dec 10, 2004 bool ok = false; TestStream testStream; PowerTabOutputStream streamOut(testStream.GetOutputStream()); // Write test data to stream KeySignature keySignatureOut(KeySignature::minorKey, KeySignature::threeFlats); keySignatureOut.Serialize(streamOut); // Output must be OK before using input if (testStream.CheckOutputState()) { PowerTabInputStream streamIn(testStream.GetInputStream()); // Read test data back from stream KeySignature keySignatureIn; keySignatureIn.Deserialize(streamIn, PowerTabFileHeader::FILEVERSION_CURRENT); // Validate the data ok = ((keySignatureIn == keySignatureOut) && (streamIn.CheckState())); } TEST(wxT("Serialize"), ok); return (true); }
void KeySignatureAction::mousePress(Staff* staff, int barIdx, const QPointF& pos) { Q_UNUSED( pos ); if (m_showDialog) { KeySignatureDialog dlg; dlg.setMusicStyle(m_tool->shape()->style()); dlg.setBar(barIdx); KeySignature* ks = staff->lastKeySignatureChange(barIdx); dlg.setAccidentals(ks ? ks->accidentals() : 0); if (dlg.exec() == QDialog::Accepted) { if (dlg.updateAllStaves()) { staff = NULL; } if (dlg.updateToNextChange() || dlg.updateTillEndOfPiece()) { SetKeySignatureCommand::RegionType t = dlg.updateToNextChange() ? SetKeySignatureCommand::NextChange : SetKeySignatureCommand::EndOfPiece; m_tool->addCommand(new SetKeySignatureCommand(m_tool->shape(), dlg.startBar(), t, staff, dlg.accidentals())); } else { m_tool->addCommand(new SetKeySignatureCommand(m_tool->shape(), dlg.startBar(), dlg.endBar(), staff, dlg.accidentals())); } } } else { m_tool->addCommand(new SetKeySignatureCommand(m_tool->shape(), barIdx, SetKeySignatureCommand::NextChange, NULL, m_accidentals)); } }
void PowerTabOldImporter::convert(const PowerTabDocument::KeySignature &oldKey, KeySignature &key) { key.setKeyType(static_cast<KeySignature::KeyType>(oldKey.GetKeyType())); key.setNumAccidentals(oldKey.GetKeyAccidentalsIncludingCancel()); key.setSharps(oldKey.UsesSharps()); key.setVisible(oldKey.IsShown()); key.setCancellation(oldKey.IsCancellation()); }
/// Tests the Key Functions /// @return True if all tests were executed, false if not bool KeySignatureTestSuite::TestCaseKey() { //------Last Checked------// // - Dec 11, 2004 KeySignature keySignature; TEST(wxT("SetKey - invalid key type"), !keySignature.SetKey(44, KeySignature::threeFlats)); TEST(wxT("SetKey - invalid key accidentals"), !keySignature.SetKey(KeySignature::minorKey, 44)); TEST(wxT("SetKey - valid"), keySignature.SetKey(KeySignature::minorKey, KeySignature::threeFlats) && (keySignature.GetKeyType() == KeySignature::minorKey) && (keySignature.GetKeyAccidentals() == KeySignature::threeFlats) ); // TEST CASE: IsSameKey { KeySignature keySignature(KeySignature::minorKey, KeySignature::threeFlats); keySignature.Show(); KeySignature keySignature2(KeySignature::minorKey, KeySignature::threeFlats); KeySignature keySignature3(KeySignature::majorKey, KeySignature::threeFlats); KeySignature keySignature4(KeySignature::minorKey, KeySignature::fourFlats); TEST(wxT("IsSameKey - true"), keySignature.IsSameKey(keySignature2)); TEST(wxT("IsSameKey - false"), !keySignature.IsSameKey(keySignature3)); TEST(wxT("IsSameKey - false"), !keySignature.IsSameKey(keySignature4)); } return (true); }
/// Tests the Cancellation Functions /// @return True if all tests were executed, false if not bool KeySignatureTestSuite::TestCaseCancellation() { //------Last Checked------// // - Dec 11, 2004 KeySignature keySignature; keySignature.SetCancellation(); TEST(wxT("SetCancellation - true"), keySignature.IsCancellation()); keySignature.SetCancellation(false); TEST(wxT("SetCancellation - false"), !keySignature.IsCancellation()); return (true); }
/// Tests the Show Functions /// @return True if all tests were executed, false if not bool KeySignatureTestSuite::TestCaseShow() { //------Last Checked------// // - Dec 11, 2004 KeySignature keySignature; keySignature.Show(); TEST(wxT("Show - true"), keySignature.IsShown()); keySignature.Hide(); TEST(wxT("Show - false"), !keySignature.IsShown()); return (true); }
void NoteEntryAction::mousePress(Staff* staff, int bar, const QPointF& pos) { Clef* clef = staff->lastClefChange(bar); Voice* voice = staff->part()->voice(m_tool->voice()); VoiceBar* vb = voice->bar(bar); // find element before which to insert the chord int before = 0; for (int i = 0; i < vb->elementCount(); i++) { VoiceElement* e = vb->element(i); if (e->x() >= pos.x()) break; before++; } int line = staff->line(pos.y()); int pitch = 0, accidentals = 0; if (clef && !m_isRest) { pitch = clef->lineToPitch(line); // get correct accidentals for note KeySignature* ks = staff->lastKeySignatureChange(bar); if (ks) accidentals = ks->accidentals(pitch); for (int i = 0; i < before; i++) { Chord* c = dynamic_cast<Chord*>(vb->element(i)); if (!c) continue; for (int n = 0; n < c->noteCount(); n++) { if (c->note(n)->pitch() == pitch) { accidentals = c->note(n)->accidentals(); } } } } Chord* join = NULL; if (before > 0) join = dynamic_cast<Chord*>(vb->element(before-1)); if (join && join->x() + join->width() >= pos.x()) { if (clef && !m_isRest) { m_tool->addCommand(new AddNoteCommand(m_tool->shape(), join, staff, m_duration, pitch, accidentals)); } else { m_tool->addCommand(new MakeRestCommand(m_tool->shape(), join)); } } else { if (clef && !m_isRest) { m_tool->addCommand(new CreateChordCommand(m_tool->shape(), vb, staff, m_duration, before, pitch, accidentals)); } else { m_tool->addCommand(new CreateChordCommand(m_tool->shape(), vb, staff, m_duration, before)); } } }
/// Tests the Flag Functions /// @return True if all tests were executed, false if not bool KeySignatureTestSuite::TestCaseFlag() { //------Last Checked------// // - Dec 13, 2004 const int testValueCount = 3; wxUint32 testValues[testValueCount]; testValues[0] = KeySignature::show; testValues[1] = KeySignature::cancellation; testValues[2] = 255; KeySignature keySignature; int i = 0; for (; i < testValueCount; i++) { keySignature.SetFlag(testValues[i]); TEST(wxString::Format(wxT("SetFlag - 0x%x"), testValues[i]), ((keySignature.SetFlag(testValues[i]) == (i < 2)) && (keySignature.IsFlagSet(testValues[i]) == (i < 2)))); } return (true); }
/// Tests the Constructors /// @return True if all tests were executed, false if not bool KeySignatureTestSuite::TestCaseConstructor() { //------Last Checked------// // - Dec 11, 2004 // TEST CASE: Default Constructor { KeySignature keySignature; TEST(wxT("Default Constructor"), (keySignature.IsMajorKey()) && (keySignature.IsMajorKey()) && (!keySignature.IsShown()) && (!keySignature.IsCancellation()) ); } // TEST CASE: Primary Constructor { KeySignature keySignature(KeySignature::minorKey, KeySignature::threeFlats); TEST(wxT("Primary Constructor"), (keySignature.IsMinorKey()) && (keySignature.HasThreeFlats()) && (!keySignature.IsShown()) && (!keySignature.IsCancellation()) ); } // TEST CASE: Copy Constructors { KeySignature keySignature(KeySignature::minorKey, KeySignature::threeFlats); KeySignature keySignature2(keySignature); TEST(wxT("Copy Constructor"), (keySignature2.IsMinorKey()) && (keySignature2.HasThreeFlats()) && (!keySignature.IsShown()) && (!keySignature.IsCancellation()) ); } return (true); }
/// Tests the Key Type Functions /// @return True if all tests were executed, false if not bool KeySignatureTestSuite::TestCaseKeyType() { //------Last Checked------// // - Dec 11, 2004 // TEST CASE: IsValidKeyType { wxByte i = KeySignature::majorKey; for (; i <= (KeySignature::minorKey + 1); i++) TEST(wxString::Format(wxT("IsValidKeyType - %d"), i), (KeySignature::IsValidKeyType(i) == (i <= KeySignature::minorKey)) ); } KeySignature keySignature; wxByte i = KeySignature::majorKey; for (; i <= (KeySignature::minorKey + 1); i++) TEST(wxString::Format(wxT("SetKeyType - %d"), i), (keySignature.SetKeyType(i) == (i <= KeySignature::minorKey)) && ((i > KeySignature::minorKey) ? 1 : (keySignature.GetKeyType() == i)) ); return (true); }
void NoteEntryAction::keyPress(QKeyEvent* event, const MusicCursor& cursor) { if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { Staff* staff = cursor.staff(); //Part* part = staff->part(); //Sheet* sheet = part->sheet(); //Bar* bar = sheet->bar(cursor.bar()); Clef* clef = staff->lastClefChange(cursor.bar()); int line = cursor.line(); int pitch = 0, accidentals = 0; VoiceBar* vb = cursor.voiceBar(); if (clef) { pitch = clef->lineToPitch(line); // get correct accidentals for note KeySignature* ks = staff->lastKeySignatureChange(cursor.bar()); if (ks) accidentals = ks->accidentals(pitch); for (int i = 0; i < cursor.element(); i++) { Chord* c = dynamic_cast<Chord*>(vb->element(i)); if (!c) continue; for (int n = 0; n < c->noteCount(); n++) { if (c->note(n)->pitch() == pitch) { accidentals = c->note(n)->accidentals(); } } } } Chord* join = 0; if (cursor.element() < vb->elementCount()) join = dynamic_cast<Chord*>(vb->element(cursor.element())); if (event->modifiers() & Qt::ShiftModifier || !join) { m_tool->addCommand(new CreateChordCommand(m_tool->shape(), vb, staff, m_duration, cursor.element(), pitch, accidentals)); } else { m_tool->addCommand(new AddNoteCommand(m_tool->shape(), join, staff, join->duration(), pitch, accidentals)); } event->accept(); } }
void EditKeySignature::updateFollowingKeySignatures(const KeySignature &oldKey, const KeySignature &newKey) { Score &score = myLocation.getScore(); const int startSystem = myLocation.getSystemIndex(); for (unsigned int i = startSystem; i < score.getSystems().size(); ++i) { for (Barline &bar : score.getSystems()[i].getBarlines()) { if (i == startSystem && bar.getPosition() <= myLocation.getPositionIndex()) { continue; } const KeySignature ¤tKey = bar.getKeySignature(); if (currentKey.getKeyType() == oldKey.getKeyType() && currentKey.getNumAccidentals() == oldKey.getNumAccidentals() && currentKey.usesSharps() == oldKey.usesSharps()) { KeySignature key; key.setVisible(bar.getKeySignature().isVisible()); key.setCancellation(bar.getKeySignature().isCancellation()); key.setSharps(newKey.usesSharps()); key.setKeyType(newKey.getKeyType()); key.setNumAccidentals(newKey.getNumAccidentals()); bar.setKeySignature(key); } else { return; } } } }
void PowerTabOldImporter::convert(const PowerTabDocument::Score &oldScore, PowerTabDocument::Score::SystemConstPtr oldSystem, System &system) { // Ensure that there are a reasonable number of positions in the staff // so that things aren't too stretched out. int lastPosition = 30; // Import barlines. Barline &startBar = system.getBarlines()[0]; convert(*oldSystem->GetStartBar(), startBar); Barline &endBar = system.getBarlines()[1]; convert(*oldSystem->GetEndBar(), endBar); for (size_t i = 0; i < oldSystem->GetBarlineCount(); ++i) { Barline bar; convert(*oldSystem->GetBarline(i), bar); system.insertBarline(bar); lastPosition = std::max(lastPosition, bar.getPosition()); // Copy the key and time signature of the last bar into the end bar, // since the v2.0 file format expects this. if (i == oldSystem->GetBarlineCount() - 1) { KeySignature key = bar.getKeySignature(); key.setVisible(false); system.getBarlines().back().setKeySignature(key); TimeSignature time = bar.getTimeSignature(); time.setVisible(false); system.getBarlines().back().setTimeSignature(time); } } // Import tempo markers. std::vector<std::shared_ptr<PowerTabDocument::TempoMarker>> tempos; oldScore.GetTempoMarkersInSystem(tempos, oldSystem); for (auto &tempo : tempos) { TempoMarker marker; convert(*tempo, marker); system.insertTempoMarker(marker); } // Import alternate endings. std::vector<std::shared_ptr<PowerTabDocument::AlternateEnding>> endings; oldScore.GetAlternateEndingsInSystem(endings, oldSystem); for (auto &ending : endings) { AlternateEnding newEnding; convert(*ending, newEnding); system.insertAlternateEnding(newEnding); } // Import directions. for (size_t i = 0; i < oldSystem->GetDirectionCount(); ++i) { Direction direction; convert(*oldSystem->GetDirection(i), direction); system.insertDirection(direction); } // Import chord text symbols. for (size_t i = 0; i < oldSystem->GetChordTextCount(); ++i) { ChordText chord; convert(*oldSystem->GetChordText(i), chord); system.insertChord(chord); } std::vector<PowerTabDocument::Score::DynamicPtr> dynamics; oldScore.GetDynamicsInSystem(dynamics, oldSystem); // Import staves. for (size_t i = 0; i < oldSystem->GetStaffCount(); ++i) { // Dynamics are now stored in the staff instead of the system. std::vector<PowerTabDocument::Score::DynamicPtr> dynamicsInStaff; for (auto &dynamic : dynamics) { if (dynamic->GetStaff() == i) dynamicsInStaff.push_back(dynamic); } Staff staff; int lastPosInStaff = convert(*oldSystem->GetStaff(i), dynamicsInStaff, staff); system.insertStaff(staff); lastPosition = std::max(lastPosition, lastPosInStaff); } system.getBarlines().back().setPosition(lastPosition + 1); }
static void writeChord(KoXmlWriter& w, Chord* chord, Voice* voice, Part* part, int bar) { if (!chord->noteCount()) { w.startElement("music:note"); w.startElement("music:rest"); w.endElement(); // music:rest w.startElement("music:duration"); w.addTextNode(QString::number(chord->length())); w.endElement(); // music:duration w.startElement("music:voice"); w.addTextNode(QString::number(part->indexOfVoice(voice) + 1)); w.endElement(); // music:voice w.startElement("music:type"); w.addTextNode(durationToString(chord->duration())); w.endElement(); // music:type for (int i = 0; i < chord->dots(); i++) { w.startElement("music:dot"); w.endElement(); // music:dot } if (part->staffCount() > 1) { // only write staff info when more than one staff exists Staff* s = chord->staff(); w.startElement("music:staff"); w.addTextNode(QString::number(part->indexOfStaff(s) + 1)); w.endElement(); //music:staff } w.endElement(); // music:note } else for (int n = 0; n < chord->noteCount(); n++) { Staff* staff = chord->note(n)->staff(); w.startElement("music:note"); if (n > 0) { w.startElement("music:chord"); w.endElement(); // music:chord } w.startElement("music:pitch"); w.startElement("music:step"); int pitch = chord->note(n)->pitch(); char note = 'A' + ((((pitch + 2) % 7) + 7) % 7); w.addTextNode(QString(note)); w.endElement(); // music:step if (chord->note(n)->accidentals()) { w.startElement("music:alter"); w.addTextNode(QString::number(chord->note(n)->accidentals())); w.endElement(); // music:alter } w.startElement("music:octave"); w.addTextNode(QString::number((pitch + 4*7) / 7)); // first add, than divide to get proper rounding w.endElement(); // music:octave w.endElement(); // music:pitch w.startElement("music:duration"); w.addTextNode(QString::number(chord->length())); w.endElement(); // music:duration w.startElement("music:voice"); w.addTextNode(QString::number(part->indexOfVoice(voice) + 1)); w.endElement(); // music:voice w.startElement("music:type"); w.addTextNode(durationToString(chord->duration())); w.endElement(); // music:type for (int i = 0; i < chord->dots(); i++) { w.startElement("music:dot"); w.endElement(); // music:dot } int activeAccidentals = 0; KeySignature* ks = staff->lastKeySignatureChange(bar); if (ks) activeAccidentals = ks->accidentals(chord->note(n)->pitch()); VoiceBar* vb = chord->voiceBar(); // next check the bar for the last previous note in the same voice with the same pitch for (int e = 0; e < vb->elementCount(); e++) { Chord* c = dynamic_cast<Chord*>(vb->element(e)); if (!c) continue; if (c == chord) break; for (int nid = 0; nid < c->noteCount(); nid++) { Note* note = c->note(nid); if (note->staff() != staff) continue; if (note->pitch() == chord->note(n)->pitch()) { activeAccidentals = note->accidentals(); } } } if (chord->note(n)->accidentals() != activeAccidentals) { w.startElement("music:accidental"); switch (chord->note(n)->accidentals()) { case -2: w.addTextNode("flat-flat"); break; case -1: w.addTextNode("flat"); break; case 0: w.addTextNode("natural"); break; case 1: w.addTextNode("sharp"); break; case 2: w.addTextNode("double-sharp"); break; } w.endElement(); // music:accidental } if (part->staffCount() > 1) { // only write staff info when more than one staff exists Staff* s = chord->note(n)->staff(); w.startElement("music:staff"); w.addTextNode(QString::number(part->indexOfStaff(s) + 1)); w.endElement(); //music:staff } w.endElement(); // music:note } }
/// Tests the Key Accidentals Functions /// @return True if all tests were executed, false if not bool KeySignatureTestSuite::TestCaseKeyAccidentals() { //------Last Checked------// // - Dec 11, 2004 // TEST CASE: IsValidKeyAccidentals { wxByte i = KeySignature::noAccidentals; for (; i <= (KeySignature::sevenFlats + 1); i++) TEST(wxString::Format(wxT("IsValidKeyAccidentals - %d"), i), (KeySignature::IsValidKeyAccidentals(i) == (i <= KeySignature::sevenFlats)) ); } KeySignature keySignature; wxByte i = KeySignature::noAccidentals; for (; i <= (KeySignature::sevenFlats + 1); i++) TEST(wxString::Format(wxT("SetKeyAccidentals - %d"), i), (keySignature.SetKeyAccidentals(i) == (i <= KeySignature::sevenFlats)) && ((i > KeySignature::sevenFlats) ? 1 : (keySignature.GetKeyAccidentals() == i)) ); // TEST CASE: HasNAccidentals { KeySignature keySignature; wxByte i = KeySignature::noAccidentals; for (; i <= KeySignature::sevenFlats; i++) { keySignature.SetKeyAccidentals(i); TEST(wxString::Format(wxT("HasNoKeyAccidentals - %d"), i), (keySignature.HasNoKeyAccidentals() == (i == KeySignature::noAccidentals))); TEST(wxString::Format(wxT("HasOneSharp - %d"), i), (keySignature.HasOneSharp() == (i == KeySignature::oneSharp))); TEST(wxString::Format(wxT("HasTwoSharps - %d"), i), (keySignature.HasTwoSharps() == (i == KeySignature::twoSharps))); TEST(wxString::Format(wxT("HasThreeSharps - %d"), i), (keySignature.HasThreeSharps() == (i == KeySignature::threeSharps))); TEST(wxString::Format(wxT("HasFourSharps - %d"), i), (keySignature.HasFourSharps() == (i == KeySignature::fourSharps))); TEST(wxString::Format(wxT("HasFiveSharps - %d"), i), (keySignature.HasFiveSharps() == (i == KeySignature::fiveSharps))); TEST(wxString::Format(wxT("HasSixSharps - %d"), i), (keySignature.HasSixSharps() == (i == KeySignature::sixSharps))); TEST(wxString::Format(wxT("HasSevenSharps - %d"), i), (keySignature.HasSevenSharps() == (i == KeySignature::sevenSharps))); TEST(wxString::Format(wxT("HasOneFlat - %d"), i), (keySignature.HasOneFlat() == (i == KeySignature::oneFlat))); TEST(wxString::Format(wxT("HasTwoFlats - %d"), i), (keySignature.HasTwoFlats() == (i == KeySignature::twoFlats))); TEST(wxString::Format(wxT("HasThreeFlats - %d"), i), (keySignature.HasThreeFlats() == (i == KeySignature::threeFlats))); TEST(wxString::Format(wxT("HasFourFlats - %d"), i), (keySignature.HasFourFlats() == (i == KeySignature::fourFlats))); TEST(wxString::Format(wxT("HasFiveFlats - %d"), i), (keySignature.HasFiveFlats() == (i == KeySignature::fiveFlats))); TEST(wxString::Format(wxT("HasSixFlats - %d"), i), (keySignature.HasSixFlats() == (i == KeySignature::sixFlats))); TEST(wxString::Format(wxT("HasSevenFlats - %d"), i), (keySignature.HasSevenFlats() == (i == KeySignature::sevenFlats))); } } return (true); }