Example #1
0
//---------------------------------------------------------
//   updateExample
//---------------------------------------------------------
void EditDrumset::updateExample()
      {
      int pitch = pitchList->currentItem()->data(0, Qt::UserRole).toInt();
      if (!nDrumset.isValid(pitch)) {
            drumNote->add(0,  0, "");
            return;
            }
      int line      = nDrumset.line(pitch);
      NoteHead::Group noteHead = nDrumset.noteHead(pitch);
      int voice     = nDrumset.voice(pitch);
      Direction dir = nDrumset.stemDirection(pitch);
      bool up = (Direction::UP == dir) || (Direction::AUTO == dir && line > 4);
      Chord* chord = new Chord(gscore);
      chord->setDurationType(TDuration::DurationType::V_QUARTER);
      chord->setStemDirection(dir);
      chord->setTrack(voice);
      chord->setUp(up);
      Note* note = new Note(gscore);
      note->setParent(chord);
      note->setTrack(voice);
      note->setPitch(pitch);
      note->setTpcFromPitch();
      note->setLine(line);
      note->setPos(0.0, gscore->spatium() * .5 * line);
      note->setHeadType(NoteHead::Type::HEAD_QUARTER);
      note->setHeadGroup(noteHead);
      note->setCachedNoteheadSym(Sym::name2id(quarterCmb->currentData().toString()));
      chord->add(note);
      Stem* stem = new Stem(gscore);
      stem->setLen((up ? -3.0 : 3.0) * gscore->spatium());
      chord->add(stem);
      drumNote->add(0,  chord, qApp->translate("drumset", nDrumset.name(pitch).toUtf8().constData()));
      }
Example #2
0
void Lilypond::addNote(const LNote& lnote)
      {
      createMeasure();

      Segment* segment = new Segment(measure);
      segment->setSubtype(SegChordRest);
      segment->setTick(tick);
      segment->setParent(measure);
      measure->add(segment);

      Chord* chord = new Chord(score);
      chord->setTrack(staff->idx() * VOICES);
      chord->setParent(segment);
      Duration d;
      d.setVal(lnote.len);
      chord->setDurationType(d);

      segment->add(chord);

      Note* note = new Note(score);
      note->setPitch(lnote.pitch);
      note->setTpcFromPitch();
      note->setParent(chord);
      note->setTrack(staff->idx() * VOICES);
      chord->add(note);
      tick += lnote.len;
      }
Example #3
0
void DrumTools::setDrumset(Score* s, Staff* st, Drumset* ds)
      {
      if (s == _score && staff == st && drumset == ds)
            return;
      _score  = s;
      staff   = st;
      drumset = ds;
      drumPalette->clear();
      if (drumset == 0)
            return;
      int drumInstruments = 0;
      for (int pitch = 0; pitch < 128; ++pitch) {
            if (drumset->isValid(pitch))
                  ++drumInstruments;
            }
      int i = 0;
      double _spatium = gscore->spatium();
      for (int pitch = 0; pitch < 128; ++pitch) {
            if (!ds->isValid(pitch))
                  continue;
            bool up;
            int line      = ds->line(pitch);
            int noteHead  = ds->noteHead(pitch);
            int voice     = ds->voice(pitch);
            Direction dir = ds->stemDirection(pitch);
            if (dir == UP)
                  up = true;
            else if (dir == DOWN)
                  up = false;
            else
                  up = line > 4;

            Chord* chord = new Chord(gscore);
            chord->setDurationType(Duration::V_QUARTER);
            chord->setStemDirection(dir);
            chord->setTrack(voice);
            Note* note = new Note(gscore);
            note->setParent(chord);
            note->setTrack(voice);
            note->setPitch(pitch);
            note->setTpcFromPitch();
            note->setLine(line);
            note->setPos(0.0, _spatium * .5 * line);
            note->setHeadGroup(noteHead);
            chord->add(note);
            Stem* stem = new Stem(gscore);
            stem->setLen((up ? -3.0 : 3.0) * _spatium);
            chord->setStem(stem);
            stem->setPos(note->stemPos(up));
            int sc = drumset->shortcut(pitch);
            QString shortcut;
            if (sc)
                  shortcut = QChar(sc);
            drumPalette->append(chord, qApp->translate("drumset", qPrintable(drumset->name(pitch))), shortcut);
            ++i;
            }
      }
Example #4
0
void MTrack::processPendingNotes(QList<MidiChord> &midiChords,
                                 int voice,
                                 const Fraction &startChordTickFrac,
                                 const Fraction &nextChordTick)
      {
      Score* score     = staff->score();
      int track        = staff->idx() * VOICES + voice;
      Drumset* drumset = staff->part()->instr()->drumset();
      bool useDrumset  = staff->part()->instr()->useDrumset();
                  // all midiChords here should have the same onTime value
                  // and all notes in each midiChord should have the same duration
      Fraction startChordTick = startChordTickFrac;
      while (!midiChords.isEmpty()) {
            Fraction tick = startChordTick;
            Fraction len = nextChordTick - tick;
            if (len <= Fraction(0))
                  break;
            len = findMinDuration(midiChords, len);
            Measure* measure = score->tick2measure(tick.ticks());
            len = splitDurationOnBarBoundary(len, tick, measure);

            auto dl = toDurationList(measure, voice, tick, len, Meter::DurationType::NOTE);
            if (dl.isEmpty())
                  break;
            const TDuration &d = dl[0].second;
            const Fraction &tupletRatio = dl[0].first;
            len = d.fraction() / tupletRatio;

            Chord* chord = new Chord(score);
            chord->setTrack(track);
            chord->setDurationType(d);
            chord->setDuration(d.fraction());
            Segment* s = measure->getSegment(chord, tick.ticks());
            s->add(chord);
            chord->setUserPlayEvents(true);
            addElementToTuplet(voice, tick, len, chord);

            for (int k = 0; k < midiChords.size(); ++k) {
                  MidiChord& midiChord = midiChords[k];
                  setMusicNotesFromMidi(score, midiChord.notes, startChordTick,
                                        len, chord, tick, drumset, useDrumset);
                  if (!midiChord.notes.empty() && midiChord.notes.first().len <= len) {
                        midiChords.removeAt(k);
                        --k;
                        continue;
                        }
                  setTies(chord, score, midiChord.notes);
                  for (auto &midiNote: midiChord.notes)
                        midiNote.len -= len;
                  }
            startChordTick += len;
            }
      fillGapWithRests(score, voice, startChordTick,
                       nextChordTick - startChordTick, track);
      }
Example #5
0
void DrumTools::updateDrumset(const Drumset* ds)
      {
      drumPalette->clear();
      drumset = ds;
      if (!drumset)
            return;
      double _spatium = gscore->spatium();
      for (int pitch = 0; pitch < 128; ++pitch) {
            if (!drumset->isValid(pitch))
                  continue;
            bool up;
            int line      = drumset->line(pitch);
            NoteHead::Group noteHead  = drumset->noteHead(pitch);
            int voice     = drumset->voice(pitch);
            Direction dir = drumset->stemDirection(pitch);
            if (dir == Direction::UP)
                  up = true;
            else if (dir == Direction::DOWN)
                  up = false;
            else
                  up = line > 4;

            Chord* chord = new Chord(gscore);
            chord->setDurationType(TDuration::DurationType::V_QUARTER);
            chord->setStemDirection(dir);
            chord->setUp(up);
            chord->setTrack(voice);
            Stem* stem = new Stem(gscore);
            stem->setLen((up ? -3.0 : 3.0) * _spatium);
            chord->add(stem);
            Note* note = new Note(gscore);
            note->setMark(true);
            note->setParent(chord);
            note->setTrack(voice);
            note->setPitch(pitch);
            note->setTpcFromPitch();
            note->setLine(line);
            note->setPos(0.0, _spatium * .5 * line);
            note->setHeadGroup(noteHead);
            SymId noteheadSym = SymId::noteheadBlack;
            if (noteHead == NoteHead::Group::HEAD_CUSTOM)
                  noteheadSym = drumset->noteHeads(pitch, NoteHead::Type::HEAD_QUARTER);
            else
                  noteheadSym = note->noteHead(true, noteHead, NoteHead::Type::HEAD_QUARTER);
            
            note->setCachedNoteheadSym(noteheadSym); // we use the cached notehead so we don't recompute it at each layout
            chord->add(note);
            int sc = drumset->shortcut(pitch);
            QString shortcut;
            if (sc)
                  shortcut = QChar(sc);
            drumPalette->append(chord, qApp->translate("drumset", drumset->name(pitch).toUtf8().data()), shortcut);
            }
      }
Example #6
0
void DrumTools::updateDrumset(const Drumset* ds)
      {
      drumPalette->clear();
      drumset = ds;
      if (!drumset)
            return;
      double _spatium = gscore->spatium();
      for (int pitch = 0; pitch < 128; ++pitch) {
            if (!drumset->isValid(pitch))
                  continue;
            bool up;
            int line      = drumset->line(pitch);
            NoteHead::Group noteHead  = drumset->noteHead(pitch);
            int voice     = drumset->voice(pitch);
            Direction dir = drumset->stemDirection(pitch);
            if (dir == Direction::UP)
                  up = true;
            else if (dir == Direction::DOWN)
                  up = false;
            else
                  up = line > 4;

            Chord* chord = new Chord(gscore);
            chord->setDurationType(TDuration::DurationType::V_QUARTER);
            chord->setStemDirection(dir);
            chord->setUp(up);
            chord->setTrack(voice);
            Note* note = new Note(gscore);
            note->setParent(chord);
            note->setTrack(voice);
            note->setPitch(pitch);
            note->setTpcFromPitch();
            note->setLine(line);
            note->setPos(0.0, _spatium * .5 * line);
            note->setHeadGroup(noteHead);
            chord->add(note);
            Stem* stem = new Stem(gscore);
            stem->setLen((up ? -3.0 : 3.0) * _spatium);
            chord->add(stem);
            stem->setPos(chord->stemPos());
            int sc = drumset->shortcut(pitch);
            QString shortcut;
            if (sc)
                  shortcut = QChar(sc);
            drumPalette->append(chord, qApp->translate("drumset", drumset->name(pitch).toLatin1().data()), shortcut);
            }
      }
Example #7
0
Chord* MCursor::addChord(int pitch, const TDuration& duration)
      {
      createMeasures();
      Measure* measure = _score->tick2measure(_tick);
      Segment* segment = measure->getSegment(Segment::Type::ChordRest, _tick);
      Chord* chord = static_cast<Chord*>(segment->element(_track));
      if (chord == 0) {
            chord = new Chord(_score);
            chord->setTrack(_track);
            chord->setDurationType(duration);
            chord->setDuration(duration.fraction());
            segment->add(chord);
            }
      Note* note = new Note(_score);
      chord->add(note);
      note->setPitch(pitch);
      note->setTpcFromPitch();
      _tick += duration.ticks();
      return chord;
      }
Example #8
0
void EditDrumset::updateExample()
      {
      int pitch = pitchList->currentItem()->data(0, Qt::UserRole).toInt();
      if (!nDrumset.isValid(pitch)) {
            drumNote->add(0,  0, "");
            return;
            }
      int line      = nDrumset.line(pitch);
      NoteHead::Group noteHead = nDrumset.noteHead(pitch);
      int voice     = nDrumset.voice(pitch);
      MScore::Direction dir = nDrumset.stemDirection(pitch);
      bool up;
      if (dir == MScore::Direction::UP)
            up = true;
      else if (dir == MScore::Direction::DOWN)
            up = false;
      else
            up = line > 4;
      Chord* chord = new Chord(gscore);
      chord->setDurationType(TDuration::DurationType::V_QUARTER);
      chord->setStemDirection(dir);
      chord->setTrack(voice);
      chord->setUp(up);
      Note* note = new Note(gscore);
      note->setParent(chord);
      note->setTrack(voice);
      note->setPitch(pitch);
      note->setTpcFromPitch();
      note->setLine(line);
      note->setPos(0.0, gscore->spatium() * .5 * line);
      note->setHeadGroup(noteHead);
      chord->add(note);
      Stem* stem = new Stem(gscore);
      stem->setLen((up ? -3.0 : 3.0) * gscore->spatium());
      chord->add(stem);
      stem->setPos(chord->stemPos());
      drumNote->add(0,  chord, qApp->translate("drumset", nDrumset.name(pitch).toUtf8().constData()));
      }
Example #9
0
void MuseData::readNote(Part* part, const QString& s)
{
    //                       a  b   c  d  e  f  g
    static int table[7]  = { 9, 11, 0, 2, 4, 5, 7 };

    int step  = s[0].toLatin1() - 'A';
    int alter = 0;
    int octave = 0;
    for (int i = 1; i < 3; ++i) {
        if (s[i] == '#')
            alter += 1;
        else if (s[i] == 'f')
            alter -= 1;
        else if (s[i].isDigit()) {
            octave = s.mid(i,1).toInt();
            break;
        }
    }
    MScore::Direction dir = MScore::AUTO;
    if (s.size() >= 23) {
        if (s[22] == 'u')
            dir = MScore::UP;
        else if (s[22] == 'd')
            dir = MScore::DOWN;
    }

    int staffIdx = 0;
    if (s.size() >= 24) {
        if (s[23].isDigit())
            staffIdx = s.mid(23,1).toInt() - 1;
    }
    Staff* staff = part->staff(staffIdx);
    int gstaff   = staff->idx();

    int pitch = table[step] + alter + (octave + 1) * 12;
    if (pitch < 0)
        pitch = 0;
    if (pitch > 127)
        pitch = 127;
    int ticks = s.mid(5, 3).toInt();
    ticks     = (ticks * MScore::division + _division/2) / _division;
    int tick  = curTick;
    curTick  += ticks;

    Tuplet* tuplet = 0;
    if (s.size() >= 22) {
        int a = 1;
        int b = 1;
        if (s[19] != ' ') {
            a = s[19].toLatin1() - '0';
            if (a == 3 && s[20] != ':')
                b = 2;
            else {
                b = s[21].toLatin1() - '0';
            }
        }
        if (a == 3 && b == 2) {       // triplet
            if (chordRest && chordRest->tuplet() && ntuplet) {
                tuplet = chordRest->tuplet();
            }
            else {
                tuplet = new Tuplet(score);
                tuplet->setTrack(gstaff * VOICES);
                tuplet->setTick(tick);
                ntuplet = a;
                tuplet->setRatio(Fraction(a, b));
                measure->add(tuplet);
            }
        }
        else if (a == 1 && b == 1)
            ;
        else
            qDebug("unsupported tuple %d/%d", a, b);
    }

    Chord* chord = new Chord(score);
    chordRest = chord;
    chord->setTrack(gstaff * VOICES);
    chord->setStemDirection(dir);
    if (tuplet) {
        chord->setTuplet(tuplet);
        tuplet->add(chord);
        --ntuplet;
    }
    TDuration d;
    d.setVal(ticks);
    chord->setDurationType(d);

    Segment* segment = measure->getSegment(chord, tick);

    voice = 0;
    for (; voice < VOICES; ++voice) {
        Element* e = segment->element(gstaff * VOICES + voice);
        if (e == 0) {
            chord->setTrack(gstaff * VOICES + voice);
            segment->add(chord);
            break;
        }
    }
    if (voice == VOICES) {
        qDebug("cannot allocate voice");
        delete chord;
        return;
    }
    Note* note = new Note(score);
    note->setPitch(pitch);
    note->setTpcFromPitch();
    note->setTrack(gstaff * VOICES + voice);
    chord->add(note);

    QString dynamics;
    QString an = s.mid(31, 11);
    for (int i = 0; i < an.size(); ++i) {
        if (an[i] == '(')
            openSlur(0, tick, staff, voice);
        else if (an[i] == ')')
            closeSlur(0, tick, staff, voice);
        else if (an[i] == '[')
            openSlur(1, tick, staff, voice);
        else if (an[i] == ']')
            closeSlur(1, tick, staff, voice);
        else if (an[i] == '{')
            openSlur(2, tick, staff, voice);
        else if (an[i] == '}')
            closeSlur(2, tick, staff, voice);
        else if (an[i] == 'z')
            openSlur(3, tick, staff, voice);
        else if (an[i] == 'x')
            closeSlur(3, tick, staff, voice);
        else if (an[i] == '.') {
            Articulation* atr = new Articulation(score);
            atr->setArticulationType(Articulation_Staccato);
            chord->add(atr);
        }
        else if (an[i] == '_') {
            Articulation* atr = new Articulation(score);
            atr->setArticulationType(Articulation_Tenuto);
            chord->add(atr);
        }
        else if (an[i] == 'v') {
            Articulation* atr = new Articulation(score);
            atr->setArticulationType(Articulation_Upbow);
            chord->add(atr);
        }
        else if (an[i] == 'n') {
            Articulation* atr = new Articulation(score);
            atr->setArticulationType(Articulation_Downbow);
            chord->add(atr);
        }
        else if (an[i] == 't') {
            Articulation* atr = new Articulation(score);
            atr->setArticulationType(Articulation_Trill);
            chord->add(atr);
        }
        else if (an[i] == 'F') {
            Articulation* atr = new Articulation(score);
            atr->setUp(true);
            atr->setArticulationType(Articulation_Fermata);
            chord->add(atr);
        }
        else if (an[i] == 'E') {
            Articulation* atr = new Articulation(score);
            atr->setUp(false);
            atr->setArticulationType(Articulation_Fermata);
            chord->add(atr);
        }
        else if (an[i] == 'O') {
            // Articulation* atr = new Articulation(score);
            // atr->setArticulationType(Articulation_Downbow);
            // chord->add(atr);
            qDebug("%06d: open string '%c' not implemented", tick, an[i].toLatin1());
        }
        else if (an[i] == '&') {
            // skip editorial level
            if (i <= an.size() && an[i+1].isDigit())
                ++i;
        }
        else if (an[i] == 'p')
            dynamics += "p";
        else if (an[i] == 'm')
            dynamics += "m";
        else if (an[i] == 'f')
            dynamics += "f";
        else if (an[i] == '-')        // tie
            ;
        else if (an[i] == '*')        // start tuplet
            ;
        else if (an[i] == '!')        // stop tuplet
            ;
        else if (an[i] == '+')        // cautionary accidental
            ;
        else if (an[i] == 'X')        // ???
            ;
        else if (an[i] == ' ')
            ;
        else {
            qDebug("%06d: notation '%c' not implemented", tick, an[i].toLatin1());
        }
    }
    if (!dynamics.isEmpty()) {
        Dynamic* dyn = new Dynamic(score);
        dyn->setDynamicType(dynamics);
        dyn->setTrack(gstaff * VOICES);
        Segment* s = measure->getSegment(Segment::SegChordRest, tick);
        s->add(dyn);
    }

    QString txt = s.mid(43, 36);
    if (!txt.isEmpty()) {
        QStringList sl = txt.split("|");
        int no = 0;
        foreach(QString w, sl) {
            w = diacritical(w);
            Lyrics* l = new Lyrics(score);
            l->setText(w);
            l->setNo(no++);
            l->setTrack(gstaff * VOICES);
            Segment* segment = measure->tick2segment(tick);
            segment->add(l);
        }
Example #10
0
void MsScWriter::note(const QString pitch, const QVector<Bww::BeamType> beamList,
                      const QString type, const int dots,
                      bool tieStart, bool /*TODO tieStop */,
                      StartStop triplet,
                      bool grace)
      {
      qDebug() << "MsScWriter::note()"
               << "type:" << type
               << "dots:" << dots
               << "grace" << grace
      ;

      if (!stepAlterOctMap.contains(pitch)
          || !typeMap.contains(type)) {
            // TODO: error message
            return;
            }
      StepAlterOct sao = stepAlterOctMap.value(pitch);

      int ticks = 4 * MScore::division / type.toInt();
      if (dots) ticks = 3 * ticks / 2;
      qDebug() << "ticks:" << ticks;
      TDuration durationType(TDuration::V_INVALID);
      durationType.setVal(ticks);
      qDebug() << "duration:" << durationType.name();
      if (triplet != ST_NONE) ticks = 2 * ticks / 3;

      BeamMode bm  = (beamList.at(0) == Bww::BM_BEGIN) ? BEAM_BEGIN : BEAM_AUTO;
      Direction sd = AUTO;

      // create chord
      Chord* cr = new Chord(score);
      //ws cr->setTick(tick);
      cr->setBeamMode(bm);
      cr->setTrack(0);
      if (grace) {
            cr->setNoteType(NOTE_GRACE32);
            cr->setDurationType(TDuration::V_32ND);
            sd = UP;
            }
      else {
            if (durationType.type() == TDuration::V_INVALID)
                  durationType.setType(TDuration::V_QUARTER);
            cr->setDurationType(durationType);
            sd = DOWN;
            }
      cr->setDuration(durationType.fraction());
      cr->setDots(dots);
      cr->setStemDirection(sd);
      // add note to chord
      Note* note = new Note(score);
      note->setTrack(0);
      xmlSetPitch(note, sao.s.toAscii(), sao.a, sao.o);
      if (tieStart) {
            Tie* tie = new Tie(score);
            note->setTieFor(tie);
            tie->setStartNote(note);
            tie->setTrack(0);
            }
      cr->add(note);
      // add chord to measure
      Segment* s = currentMeasure->getSegment(cr, tick);
      s->add(cr);
      if (!grace) {
            doTriplet(cr, triplet);
            int tickBefore = tick;
            tick += ticks;
            Fraction nl(Fraction::fromTicks(tick - currentMeasure->tick()));
            currentMeasure->setLen(nl);
            qDebug() << "MsScWriter::note()"
                     << "tickBefore:" << tickBefore
                     << "tick:" << tick
                     << "nl:" << nl.print()
            ;
            }
      }