Exemplo n.º 1
0
Note* searchTieNote114(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;

      while ((seg = seg->next1(Segment::SegChordRest))) {
            for (int track = strack; track < etrack; ++track) {
                  Chord* c = static_cast<Chord*>(seg->element(track));
                  if (c == 0 || (c->type() != Element::CHORD) || (c->track() != chord->track()))
                        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;
      }
Exemplo n.º 2
0
void Dynamic::layout()
      {
      if (!readPos().isNull()) {
            if (score()->mscVersion() < 118) {
                  setReadPos(QPointF());
                  // hack: 1.2 boundingBoxes are a bit wider which results
                  // in symbols moved right
                  setUserXoffset(userOff().x() - spatium() * .6);
                  }
            }
      Text::layout();

      Segment* s = segment();
      for (int voice = 0; voice < VOICES; ++voice) {
            int t = (track() & ~0x3) + voice;
            Chord* c = static_cast<Chord*>(s->element(t));
            if (!c)
                  continue;
            if (c->type() == CHORD) {
                  qreal noteHeadWidth = score()->noteHeadWidth() * c->mag();
                  if (c->stem() && !c->up())  // stem down
                        rxpos() += noteHeadWidth * .25;  // center on stem + optical correction
                  else
                        rxpos() += noteHeadWidth * .5;   // center on note head
                  }
            else
                  rxpos() += c->width() * .5;
            break;
            }
      }
Exemplo n.º 3
0
RelativeChord::RelativeChord(const Key& inKey, const Chord& inChord)
: m_RootInterval(inKey.tonic(), inChord.root()), m_Type(inChord.type())
{
	if (inChord == Chord::silence())
	{
		*this = silence();
	}
	else if (inChord == Chord::none())
	{
		*this = none();
	}
	else if (inChord == Chord::undefined())
	{
		*this = unknown();
	}
	if (inKey == Key::silence())
	{
		std::runtime_error("Cannot deduce relative chord when key is silence");
	}
}
Exemplo n.º 4
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;
      }
Exemplo n.º 5
0
void PianoView::updateNotes()
      {
      scene()->blockSignals(true);  // block changeSelection()
      scene()->clearFocus();
      scene()->clear();
      createLocators();

      int staffIdx   = staff->idx();
      int startTrack = staffIdx * VOICES;
      int endTrack   = startTrack + VOICES;

      Segment::Type st = Segment::Type::ChordRest;
      for (Segment* s = staff->score()->firstSegment(st); s; s = s->next1(st)) {
            for (int track = startTrack; track < endTrack; ++track) {
                  Chord* chord = static_cast<Chord*>(s->element(track));
                  if (chord == 0 || chord->type() != ElementType::CHORD)
                        continue;
                  addChord(chord);
                  }
            }
      for (int i = 0; i < 3; ++i)
            moveLocator(i);
      scene()->blockSignals(false);
      }
Exemplo n.º 6
0
RelativeChord Key::relativeChord(const Chord& inChord) const
{
	return RelativeChord(Interval(tonic(), inChord.root()), inChord.type());
}
Exemplo n.º 7
0
const double SimilarityScoreChord::score(const Chord& inRefChord, const Chord& inTestChord)
{
    this->m_RefIndex = calcChordIndex(inRefChord, this->m_MappedRefLabel);
    this->m_TestIndex = calcChordIndex(inTestChord, this->m_MappedTestLabel);
    
    // Check input and output limiting set and check for unmappable chords in reference sequence
    if ((m_InputLimitingSet.empty() || m_InputLimitingSet.count(inRefChord.type()) > 0) &&
        //(m_OutputLimitingSet.empty() || m_OutputLimitingSet.count(this->m_MappedRefLabel.type()) > 0) &&
        (this->m_RefIndex < this->m_NumOfRefLabels))
    {
        // Check for unmappable chords in test sequence
        if ((this->m_MappedTestLabel.type() == ChordType::rootOnly() ||
             this->m_MappedTestLabel.type() == ChordType::power()) &&
            m_Mapping != "root" && m_Mapping != "bass" && m_Mapping != "none")
        {
            throw invalid_argument("The chord '" + ChordQM(inTestChord).str() + "' in the test sequence cannot be mapped using the current evaluating rules");
        }
        
        if (m_Scoring == "exact")
        {
            if (this->m_RefIndex == this->m_TestIndex)
            {
                return 1.;
            }
            else
            {
                return 0.;
            }
        }
        else if (m_Scoring == "mirex2010")
        {
            size_t theNumOfCommonChromas = inRefChord.commonChromas(inTestChord).size();
            if (theNumOfCommonChromas > 2 ||
                (!inRefChord.isTrueChord() && !inTestChord.isTrueChord()) ||
                (theNumOfCommonChromas > 1 && (inRefChord.type().triad(false) == ChordType::diminished() || inRefChord.type().triad(false) == ChordType::augmented()))/* || inRefChord.type().cardinality() == theNumOfCommonChromas*/)
            {
                return 1.;
            }
            else
            {
                return 0.;
            }
        }
        else if (m_Scoring == "chromarecall")
        {
            if (inRefChord.isTrueChord())
            {
                double theNumOfCommonChromas = inRefChord.commonChromas(inTestChord).size();
                return theNumOfCommonChromas / inRefChord.type().cardinality();
            }
            else
            {
                if (!inTestChord.isTrueChord())
                {
                    return 1.;
                }
                else
                {
                    return 0.;
                }
            }
        }
        else if (m_Scoring == "chromaprecision")
        {
            if (inTestChord.isTrueChord())
            {
                double theNumOfCommonChromas = inRefChord.commonChromas(inTestChord).size();
                return theNumOfCommonChromas / inTestChord.type().cardinality();        }
            else
            {
                if (!inRefChord.isTrueChord())
                {
                    return 1.;
                }
                else
                {
                    return 0.;
                }
            }
        }
        else if (m_Scoring == "chromafmeasure")
        {
            if (inRefChord.isTrueChord() && inTestChord.isTrueChord())
            {
                double theNumOfCommonChromas = inRefChord.commonChromas(inTestChord).size();
                return 2 * theNumOfCommonChromas / (inRefChord.type().cardinality() + inTestChord.type().cardinality());        }
            else
            {
                if (!inRefChord.isTrueChord() && !inTestChord.isTrueChord())
                {
                    return 1.;
                }
                else
                {
                    return 0.;
                }
            }
        }
        else
        {
            throw runtime_error("Unknown scoring function '" + m_Scoring + "'");
        }
    }
    else
    {
        // Exclude from evaluation
        return -1.;
    }
}
Exemplo n.º 8
0
Note* searchTieNote(Note* note)
      {
      Note* note2  = 0;
      Chord* chord = note->chord();
      Segment* seg = chord->segment();
      Part* part   = chord->part();
      int strack   = part->staves()->front()->idx() * VOICES;
      int etrack   = strack + part->staves()->size() * VOICES;

      if (chord->isGraceBefore()) {
            // grace before
            // try to tie to note in parent chord
            chord = static_cast<Chord*>(chord->parent());
            note2 = chord->findNote(note->pitch());
            if (note2)
                  return note2;
            }
      else if (chord->isGraceAfter()) {
            // grace after
            // we will try to tie to note in next normal chord, below
            // meanwhile, set chord to parent chord so the endTick calculation will make sense
            chord = static_cast<Chord*>(chord->parent());
            }
      else {
            // normal chord
            // try to tie to grace note after if present
            QList<Chord*> gna = chord->graceNotesAfter();
            if (!gna.isEmpty()) {
                  Chord* gc = gna[0];
                  note2 = gc->findNote(note->pitch());
                  if (note2)
                        return note2;
                  }
            }
      // at this point, chord is a regular chord, not a grace chord
      // and we are looking for a note in the *next* chord (grace or regular)

      // calculate end of current note duration
      // but err on the safe side in case there is roundoff in tick count
      int endTick = chord->tick() + chord->actualTicks() - 1;

      while ((seg = seg->next1(Segment::Type::ChordRest))) {
            // skip ahead to end of current note duration as calculated above
            // but just in case, stop if we find element in current track
            if (seg->tick() < endTick  && !seg->element(chord->track()))
                  continue;
            for (int track = strack; track < etrack; ++track) {
                  Chord* c = static_cast<Chord*>(seg->element(track));
                  if (c == 0 || c->type() != Element::Type::CHORD)
                        continue;
                  // if there are grace notes before, try to tie to first one
                  QList<Chord*> gnb = c->graceNotesBefore();
                  if (!gnb.isEmpty()) {
                        Chord* gc = gnb[0];
                        Note* gn2 = gc->findNote(note->pitch());
                        if (gn2)
                              return gn2;
                        }
                  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;
      }