示例#1
0
ChordRest* prevChordRest(ChordRest* cr)
      {
      if (!cr)
            return 0;
      if (cr->isGrace()) {
            // cr is a grace note
            Chord* c  = static_cast<Chord*>(cr);
            Chord* pc = static_cast<Chord*>(cr->parent());
            QList<Chord*> graceNotesBefore;
            QList<Chord*> graceNotesAfter;

            if(cr->isGraceBefore()){
                  pc->getGraceNotesBefore(&graceNotesBefore);
                  auto i = std::find(graceNotesBefore.begin(),graceNotesBefore.end(), c);
                  if (i == graceNotesBefore.end())
                        return 0;
                  if (i == graceNotesBefore.begin())
                        cr = pc;
                  else
                        return *--i;
                  }
            else {
                  int n = pc->getGraceNotesAfter(&graceNotesAfter);
                  for(int i = 0; i < n; i++){
                        if(c == graceNotesAfter[(i)]){
                              if(i > 0)
                                    return graceNotesAfter[i - 1];
                              else
                                    return 0;
                              }
                        }
                  }
            }
      else {
            if (cr->type() == Element::CHORD) {
                  Chord* c = static_cast<Chord*>(cr);
                  if (!c->graceNotes().empty())
                        return c->graceNotes().back();
                  }
            }
      int track = cr->track();
      Segment::SegmentTypes st = Segment::SegChordRest;
      for (Segment* seg = cr->segment()->prev1(st); seg; seg = seg->prev1(st)) {
            ChordRest* e = static_cast<ChordRest*>(seg->element(track));
            if (e)
                  return e;
            }
      return 0;
      }
示例#2
0
Note* searchTieNote(Note* note)
      {
      Note* note2  = 0;
      Chord* chord = note->chord();
      Segment* seg = chord->segment();
      Part* part   = chord->staff()->part();
      int strack   = part->staves()->front()->idx() * VOICES;
      int etrack   = strack + part->staves()->size() * VOICES;

      if (chord->isGraceBefore()) {
            chord = static_cast<Chord*>(chord->parent());
            note2 = chord->findNote(note->pitch());
            return note2;
            }
      QList<Chord*> gna;
      if (chord->getGraceNotesAfter(&gna)) {
            chord = gna[0];
            note2 = chord->findNote(note->pitch());
            return note2;
            }

      while ((seg = seg->next1(Segment::Type::ChordRest))) {
            for (int track = strack; track < etrack; ++track) {
                  Chord* c = static_cast<Chord*>(seg->element(track));
                  if (c == 0 || c->type() != Element::Type::CHORD)
                        continue;
                  int staffIdx = c->staffIdx() + c->staffMove();
                  if (staffIdx != chord->staffIdx() + chord->staffMove())  // cannot happen?
                        continue;
                  for (Note* n : c->notes()) {
                        if (n->pitch() == note->pitch()) {
                              if (note2 == 0 || c->track() == chord->track())
                                    note2 = n;
                              }
                        }
                  }
            if (note2)
                  break;
            }
      return note2;
      }
示例#3
0
ChordRest* nextChordRest(ChordRest* cr)
      {
      if (!cr)
            return 0;

      if (cr->isGrace()) {
            //
            // cr is a grace note

            Chord* c  = static_cast<Chord*>(cr);
            Chord* pc = static_cast<Chord*>(cr->parent());

            if (cr->isGraceBefore()) {
                  QList<Chord*> graceNotesBefore;
                  pc->getGraceNotesBefore(&graceNotesBefore);
                  auto i = std::find(graceNotesBefore.begin(), graceNotesBefore.end(), c);
                  if (i == graceNotesBefore.end())
                        return 0;   // unable to find self?
                  ++i;
                  if (i != graceNotesBefore.end())
                        return *i;
                  // if this was last grace note before, return parent
                  return pc;
                  }
            else {
                  QList<Chord*> graceNotesAfter;
                  pc->getGraceNotesAfter(&graceNotesAfter);
                  auto i = std::find(graceNotesAfter.begin(), graceNotesAfter.end(), c);
                  if (i == graceNotesAfter.end())
                        return 0;   // unable to find self?
                  ++i;
                  if (i != graceNotesAfter.end())
                        return *i;
                  // if this was last grace note after, fall through to find next main note
                  cr = pc;
                  }
            }
      else {
            //
            // cr is not a grace note
            if (cr->type() == Element::Type::CHORD) {
                  Chord* c = static_cast<Chord*>(cr);
                  if (!c->graceNotes().empty()) {
                        QList<Chord*> graceNotesAfter;
                        c->getGraceNotesAfter(&graceNotesAfter);
                        if (!graceNotesAfter.isEmpty())
                              return graceNotesAfter.first();
                        }
                  }
            }

      int track = cr->track();
      Segment::Type st = Segment::Type::ChordRest;

      for (Segment* seg = cr->segment()->next1MM(st); seg; seg = seg->next1MM(st)) {
            ChordRest* e = static_cast<ChordRest*>(seg->element(track));
            if (e) {
                  if (e->type() == Element::Type::CHORD) {
                        Chord* c = static_cast<Chord*>(e);
                        if (!c->graceNotes().empty()) {
                              QList<Chord*> graceNotesBefore;
                              c->getGraceNotesBefore(&graceNotesBefore);
                              if (!graceNotesBefore.isEmpty())
                                    return graceNotesBefore.first();
                              }
                        }
                  return e;
                  }
            }

      return 0;
      }