コード例 #1
0
ファイル: importgtp-gp5.cpp プロジェクト: jpirie/MuseScore
int GuitarPro5::readBeat(int tick, int voice, Measure* measure, int staffIdx, Tuplet** tuplets, bool /*mixChange*/)
      {
      uchar beatBits = readUChar();
      bool dotted    = beatBits & BEAT_DOTTED;

      slide = -1;
      int track = staffIdx * VOICES + voice;
      if (slides.contains(track))
            slide = slides.take(track);

      int pause = -1;
      if (beatBits & BEAT_PAUSE)
            pause = readUChar();

      // readDuration
      int len   = readChar();
      int tuple = 0;
      if (beatBits & BEAT_TUPLET)
            tuple = readInt();

      Segment* segment = measure->getSegment(Segment::Type::ChordRest, tick);
      if (beatBits & BEAT_CHORD) {
            int numStrings = score->staff(staffIdx)->part()->instr()->stringData()->strings();
            skip(17);
            QString name = readPascalString(21);
            skip(4);
            // no header to be read in the GP5 format - default to true.
            readChord(segment, staffIdx * VOICES, numStrings, name, true);
            skip(32);
            }
      Lyrics* lyrics = 0;
      if (beatBits & BEAT_LYRICS) {
            QString txt = readDelphiString();
            lyrics = new Lyrics(score);
            lyrics->setText(txt);
            }
      gpLyrics.beatCounter++;
      if (gpLyrics.beatCounter >= gpLyrics.fromBeat && gpLyrics.lyricTrack == staffIdx+1) {
            int index = gpLyrics.beatCounter - gpLyrics.fromBeat;
            if (index < gpLyrics.lyrics.size()) {
                  lyrics = new Lyrics(score);
                  lyrics->setText(gpLyrics.lyrics[index]);
                  }
            }
      int beatEffects = 0;
      if (beatBits & BEAT_EFFECTS)
            beatEffects = readBeatEffects(track, segment);

      if (beatBits & BEAT_MIX_CHANGE)
            readMixChange(measure);

      int strings = readUChar();   // used strings mask

      Fraction l    = len2fraction(len);

      // Some beat effects could add a Chord before this
      ChordRest* cr = segment->cr(track);
      if (voice != 0 && pause == 0 && strings == 0)
            cr = 0;
      else {
            if (strings == 0) {
                  if (cr) {
                        segment->remove(cr);
                        delete cr;
                        cr = 0;
                        }
                  cr = new Rest(score);
                  }
            else  {
                  if (!cr)
                        cr = new Chord(score);
                  }
            cr->setTrack(track);

            TDuration d(l);
            d.setDots(dotted ? 1 : 0);

            if (dotted)
                  l = l + (l/2);

            if (tuple) {
                  Tuplet* tuplet = tuplets[staffIdx * 2 + voice];
                  if ((tuplet == 0) || (tuplet->elementsDuration() == tuplet->baseLen().fraction() * tuplet->ratio().numerator())) {
                        tuplet = new Tuplet(score);
                        // int track = staffIdx * 2 + voice;
                        tuplets[staffIdx * 2 + voice] = tuplet;
                        tuplet->setTrack(cr->track());
                        setTuplet(tuplet, tuple);
                        tuplet->setParent(measure);
                        }
                  tuplet->setTrack(cr->track());
                  tuplet->setBaseLen(l);
                  tuplet->setDuration(l * tuplet->ratio().denominator());
                  cr->setTuplet(tuplet);
                  tuplet->add(cr);
                  }

            cr->setDuration(l);
            if (cr->type() == Element::Type::REST && (pause == 0 || l == measure->len()))
                  cr->setDurationType(TDuration::DurationType::V_MEASURE);
            else
                  cr->setDurationType(d);

            if(!segment->cr(track))
                  segment->add(cr);

            Staff* staff = cr->staff();
            int numStrings = staff->part()->instr()->stringData()->strings();
            bool hasSlur = false;
            for (int i = 6; i >= 0; --i) {
                  if (strings & (1 << i) && ((6-i) < numStrings)) {
                        Note* note = new Note(score);
                        if (dotted) {
                              // there is at most one dotted note in this guitar pro version
                              NoteDot* dot = new NoteDot(score);
                              dot->setIdx(0);
                              dot->setParent(note);
                              dot->setTrack(track);  // needed to know the staff it belongs to (and detect tablature)
                              dot->setVisible(true);
                              note->add(dot);
                              }
                        static_cast<Chord*>(cr)->add(note);

                        hasSlur = readNote(6-i, note);
                        note->setTpcFromPitch();
                        }
                  }
            createSlur(hasSlur, staffIdx, cr);
            if (lyrics)
                  cr->add(lyrics);
            }
      int rr = readChar();
      if (cr && (cr->type() == Element::Type::CHORD)) {
            Chord* chord = static_cast<Chord*>(cr);
            applyBeatEffects(chord, beatEffects);
            if (rr == ARPEGGIO_DOWN)
                  chord->setStemDirection(MScore::Direction::DOWN);
            else if (rr == ARPEGGIO_UP)
                  chord->setStemDirection(MScore::Direction::UP);
            }
      int r = readChar();
      if (r & 0x8) {
            int rrr = readChar();
qDebug("  3beat read 0x%02x", rrr);
           }
      if (cr && (cr->type() == Element::Type::CHORD) && slide > 0)
            createSlide(slide, cr, staffIdx);
      restsForEmptyBeats(segment, measure, cr, l, track, tick);
      return cr ? cr->actualTicks() : measure->ticks();
      }
コード例 #2
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);
        }