Example #1
0
QJsonObject SymbolBehavior::toJson() const
{
    QJsonObject json(ItemBehavior::toJson());

    int symbolType = data(LP::SymbolType).toInt();
    if (symbolType != LP::NoSymbolType) {
        json.insert(DataKey::SymbolType, symbolType);
    }
    json.insert(DataKey::Instrument, data(LP::SymbolInstrument).toInt());
    json.insert(DataKey::SymbolName, data(LP::SymbolName).toString());
    if (hasOption(HasLength)) {
        Length::Value length = data(LP::SymbolLength).value<Length::Value>();
        json.insert(DataKey::Lenght, static_cast<int>(length));
    }
    if (hasOption(HasPitch)) {
        Pitch pitch = data(LP::SymbolPitch).value<Pitch>();
        json.insert(DataKey::Pitch, pitch.toJson());
    }
    SpanType spanType = data(LP::SymbolSpanType).value<SpanType>();

    if (spanType != SpanType::None) {
        json.insert(DataKey::SymbolSpanType, static_cast<int>(spanType));
    }

    return json;
}
Example #2
0
void SymbolBehavior::fromJson(const QJsonObject &json)
{
    ItemBehavior::fromJson(json);

    int type = json.value(DataKey::SymbolType).toInt();
    setData(type, LP::SymbolType);

    int instrument = json.value(DataKey::Instrument).toInt();
    setData(instrument, LP::SymbolInstrument);

    QString name = json.value(DataKey::SymbolName).toString();
    setData(name, LP::SymbolName);

    if (hasOption(HasLength)) {
        int length = json.value(DataKey::Lenght).toInt();
        Length::Value lengthValue = static_cast<Length::Value>(length);
        setData(QVariant::fromValue<Length::Value>(lengthValue), LP::SymbolLength);
    }

    if (hasOption(HasPitch)) {
        QJsonObject pitchObject = json.value(DataKey::Pitch).toObject();
        Pitch pitch;
        pitch.fromJson(pitchObject);
        setData(QVariant::fromValue<Pitch>(pitch), LP::SymbolPitch);
    }

    int spanType = json.value(DataKey::SymbolSpanType).toInt();
    if (spanType != 0) {
        SpanType type = static_cast<SpanType>(spanType);
        setData(QVariant::fromValue<SpanType>(type), LP::SymbolSpanType);
    }
}
Example #3
0
bool Pitch::operator==( const Pitch &orig ){
  if( m_note == orig.getNoteName() &&
      m_acc == orig.getAccidental() && 
      m_oct == orig.getOctave() )
    return true;
  else
    return false;
}
Example #4
0
void TestTranspose::testTransposeBbToF()
{
    Pitch bb(70, Accidentals::Flat);
    Key besmaj("Bb major");
    Pitch result = bb.transpose(besmaj, -5, -3);

    Accidental resultAccidental = result.getAccidental(besmaj);
    int resultPitch = result.getPerformancePitch();
    QCOMPARE(resultAccidental, Accidentals::NoAccidental);
    QCOMPARE(resultPitch, 65);
}
Example #5
0
/** 
 * transpose an C# down by an augmented prime in C# major, should yield a C (in C major)
 */
void TestTranspose::testCisToC()
{
    // Testing transposing C# to C

    Pitch cis(73, Accidentals::Sharp);
    Pitch result = cis.transpose(Key("C# major"), -1, 0);

    Accidental resultAccidental = result.getAccidental(Key("C major"));
    int resultPitch = result.getPerformancePitch();
    QCOMPARE(resultAccidental, Accidentals::NoAccidental);
    QCOMPARE(resultPitch, 72);
}
Example #6
0
/**
 * Transpose G to D in the key of D major.
 */
void TestTranspose::testGToD()
{
    // Testing transposing G to D
    Pitch g(67, Accidentals::Natural);
    Key* dmaj = new Key("D major");

    Pitch result = g.transpose(*dmaj, 7, 4);

    Accidental resultAccidental = result.getAccidental(*dmaj);
    int resultPitch = result.getPerformancePitch();
    QCOMPARE(resultAccidental, Accidentals::NoAccidental);
    QCOMPARE(resultPitch, 74);
}
Example #7
0
/** 
 * transpose an A# up by a major second, should 
 * yield a B# (as C would be a minor triad) 
 */
void TestTranspose::testAisToBis()
{
    // Testing transposing A# to B#
    Pitch ais(70, Accidentals::Sharp);
    Key cmaj ("C major");

    Pitch result = ais.transpose(cmaj, 2, 1);

    Accidental resultAccidental = result.getAccidental(cmaj);
    int resultPitch = result.getPerformancePitch();
    QCOMPARE(resultAccidental, Accidentals::Sharp);
    QCOMPARE(resultPitch, 72);
}
bool MelodyNoteGraphicBuilder::isPitchOnLine(const Pitch &pitch) const
{
    if (pitch.staffPos() % 2) {
        return false;
    }
    return true;
}
void MelodyNoteGraphicBuilder::setLedgerLinesForPitch(const Pitch &pitch)
{
    if (m_pitchContext.isNull())
        return;

    int staffPos = pitch.staffPos();
    int ledgerLineCount = ledgerLineCountForStaffPos(staffPos);
    m_glyph->setLedgerLines(ledgerLineCount, staffPos < 0);
}
Example #10
0
bool Pitch::operator!=( const Pitch &orig ){
  if( m_note != orig.getNoteName() ) return true;
  if( m_acc != orig.getAccidental() ) return true;
  if( m_oct != orig.getOctave() ) return true;
  else return false;
}
Example #11
0
void
TrackParameterBox::updateWidgets2()
{
    Track *track = getTrack();
    if (!track)
        return;

    Instrument *instrument = m_doc->getStudio().getInstrumentFor(track);
    if (!instrument)
        return;

    // *** Track Label

    QString trackName = strtoqstr(track->getLabel());
    if (trackName.isEmpty())
        trackName = tr("<untitled>");
    else
        trackName.truncate(20);

    const int trackNum = track->getPosition() + 1;

    m_trackLabel->setText(tr("[ Track %1 - %2 ]").arg(trackNum).arg(trackName));

    // *** Playback parameters

    // Device
    updatePlaybackDevice(instrument->getDevice()->getId());

    // Instrument
    updateInstrument(instrument);

    // Archive
    m_archive->setChecked(track->isArchived());

    // If the current Instrument is an Audio Instrument...
    if (instrument->getInstrumentType() == Instrument::Audio) {

        // Hide irrelevant portions.

        m_recordingFiltersFrame->setVisible(false);
        m_staffExportOptionsFrame->setVisible(false);

        // In the Create segments with... frame, only the color combo is
        // useful for an Audio track.
        m_presetLabel->setVisible(false);
        m_preset->setVisible(false);
        m_load->setVisible(false);
        m_clefLabel->setVisible(false);
        m_clef->setVisible(false);
        m_transposeLabel->setVisible(false);
        m_transpose->setVisible(false);
        m_pitchLabel->setVisible(false);
        m_lowestLabel->setVisible(false);
        m_lowest->setVisible(false);
        m_highestLabel->setVisible(false);
        m_highest->setVisible(false);

    } else {  // MIDI or soft synth

        // Show everything.

        m_recordingFiltersFrame->setVisible(true);
        m_staffExportOptionsFrame->setVisible(true);

        // Create segments with... frame
        m_presetLabel->setVisible(true);
        m_preset->setVisible(true);
        m_load->setVisible(true);
        m_clefLabel->setVisible(true);
        m_clef->setVisible(true);
        m_transposeLabel->setVisible(true);
        m_transpose->setVisible(true);
        m_pitchLabel->setVisible(true);
        m_lowestLabel->setVisible(true);
        m_lowest->setVisible(true);
        m_highestLabel->setVisible(true);
        m_highest->setVisible(true);
    }

    // *** Recording filters

    // Device
    updateRecordingDevice(track->getMidiInputDevice());

    // Channel
    m_recordingChannel->setCurrentIndex((int)track->getMidiInputChannel() + 1);

    // Thru Routing
    m_thruRouting->setCurrentIndex((int)track->getThruRouting());

    // *** Staff export options

    // Notation size
    m_notationSize->setCurrentIndex(track->getStaffSize());

    // Bracket type
    m_bracketType->setCurrentIndex(track->getStaffBracket());

    // *** Create segments with

    // Preset (Label)
    m_preset->setText(strtoqstr(track->getPresetLabel()));

    // Clef
    m_clef->setCurrentIndex(track->getClef());

    // Transpose
    m_transpose->setCurrentIndex(
            m_transpose->findText(QString("%1").arg(track->getTranspose())));

    // Pitch Lowest

    QSettings settings;
    settings.beginGroup(GeneralOptionsConfigGroup);
    const int octaveBase = settings.value("midipitchoctave", -2).toInt() ;
    settings.endGroup();

    const bool includeOctave = false;

    const Pitch lowest(track->getLowestPlayable(), Accidentals::NoAccidental);

    // NOTE: this now uses a new, overloaded version of Pitch::getAsString()
    // that explicitly works with the key of C major, and does not allow the
    // calling code to specify how the accidentals should be written out.
    //
    // Separate the note letter from the octave to avoid undue burden on
    // translators having to retranslate the same thing but for a number
    // difference
    QString tmp = QObject::tr(lowest.getAsString(includeOctave, octaveBase).c_str(), "note name");
    tmp += tr(" %1").arg(lowest.getOctave(octaveBase));
    m_lowest->setText(tmp);

    // Pitch Highest

    const Pitch highest(track->getHighestPlayable(), Accidentals::NoAccidental);

    tmp = QObject::tr(highest.getAsString(includeOctave, octaveBase).c_str(), "note name");
    tmp += tr(" %1").arg(highest.getOctave(octaveBase));
    m_highest->setText(tmp);

    // Color
    // Note: We only update the combobox contents if there is an actual
    //       change to the document's colors.  See slotDocColoursChanged().
    m_color->setCurrentIndex(track->getColor());
}