Ejemplo n.º 1
0
void MuseScore::tupletDialog()
      {
      if (!cs)
            return;
      ChordRest* cr = cs->getSelectedChordRest();
      if (cr == 0)
            return;
      TupletDialog td;
      if (!td.exec())
            return;

      Tuplet* tuplet = new Tuplet(cs);
      tuplet->setTrack(cr->track());
      tuplet->setTick(cr->tick());
      td.setupTuplet(tuplet);
      //      tuplet->setRatio(tuplet->ratio().reduced());
      Fraction f1(cr->duration());
      tuplet->setDuration(f1);
      Fraction f = f1 * tuplet->ratio();
      f.reduce();

      printf("len %s  ratio %s  base %s\n",
         qPrintable(f1.print()),
         qPrintable(tuplet->ratio().print()),
         qPrintable(f.print()));

      tuplet->setBaseLen(Fraction(1, f.denominator()));

      Measure* measure = cr->measure();
      tuplet->setParent(measure);

      cs->cmdCreateTuplet(cr, tuplet);
      }
Ejemplo n.º 2
0
QPointF Articulation::pagePos() const
      {
      if (parent() == 0 || parent()->parent() == 0)
            return pos();
      if (parent()->isChordRest()) {
            ChordRest* cr = static_cast<ChordRest*>(parent());
            Measure* m = cr->measure();
            if (m == 0)
                  return pos();
            System* system = m->system();
            if (system == 0)
                  return pos();
            qreal yp = y() + system->staff(staffIdx() + cr->staffMove())->y() + system->y();
            return QPointF(pageX(), yp);
            }
      return Element::pagePos();
      }
Ejemplo n.º 3
0
void SwingDetector::applySwing()
      {
      if (elements.size() != 2 && elements.size() != 3)
            return;

      Tuplet *tuplet = nullptr;
      for (ChordRest *el: elements) {
            el->setDurationType(TDuration::DurationType::V_EIGHTH);
            el->setTicks(Fraction(1, 8));
            el->setDots(0);
            if (el->tuplet()) {
                  if (!tuplet)
                        tuplet = el->tuplet();
                  tuplet->remove(el);
                  el->setTuplet(nullptr);
                  }
            }

      const ChordRest *first = elements.front();
      const int startTick = first->segment()->tick().ticks();
      ChordRest *last = elements.back();
      last->segment()->remove(last);
      Segment *s = last->measure()->getSegment(SegmentType::ChordRest, Fraction::fromTicks(startTick + MScore::division / 2));
      s->add(last);

      if (elements.size() == 3) {
                  // remove central rest
            ChordRest *cr = elements[1];
            cr->score()->removeElement(cr);
            delete cr;
            }

      if (tuplet) {
                  // delete tuplet
            delete tuplet;
            tuplet = nullptr;
            }
      if (!swingApplied)
            swingApplied = true;
      }
Ejemplo n.º 4
0
void Slur::slurPos(SlurPos* sp)
      {
      qreal _spatium = spatium();
      Element* e1 = startElement();
      Element* e2 = endElement();

      if (e2 == 0) {
            sp->p1 = e1->pagePos();
            sp->p1.rx() += e1->width();
            sp->p2 = sp->p1;
            sp->p2.rx() += 5 * _spatium;
            sp->system1 = static_cast<ChordRest*>(e1)->measure()->system();
            sp->system2 = sp->system1;
            return;
            }

      ChordRest* scr   = static_cast<ChordRest*>(e1);
      ChordRest* ecr   = static_cast<ChordRest*>(e2);
      Chord* sc   = 0;
      Note* note1 = 0;
      if(e1->type() == CHORD) {
            sc = static_cast<Chord*>(e1);
            note1 = _up ? sc->upNote() : sc->downNote();
            }
      Chord* ec = 0;
      Note* note2 = 0;
      if(e2->type() == CHORD) {
            ec   = static_cast<Chord*>(e2);
            note2 = _up ? ec->upNote() : ec->downNote();
            }

      sp->system1 = scr->measure()->system();
      sp->system2 = ecr->measure()->system();
      sp->p1      = scr->pagePos() - sp->system1->pagePos();
      sp->p2      = ecr->pagePos() - sp->system2->pagePos();

      qreal xo, yo;

      Stem* stem1 = sc?sc->stem():0;
      Stem* stem2 = ec?ec->stem():0;

      enum SlurAnchor {
            SA_NONE, SA_STEM
            };
      SlurAnchor sa1 = SA_NONE;
      SlurAnchor sa2 = SA_NONE;
      if ((scr->up() == ecr->up()) && !scr->beam() && !ecr->beam() && (_up == scr->up())) {
            if (stem1)
                  sa1 = SA_STEM;
            if (stem2)
                  sa2 = SA_STEM;
            }

      qreal __up = _up ? -1.0 : 1.0;
      qreal hw   = note1?note1->headWidth():e1->width();
      switch (sa1) {
            case SA_STEM: //sc can't be null
                  sp->p1 += sc->stemPosBeam() - sc->pagePos() + sc->stem()->p2();
                  sp->p1 += QPointF(0.35 * _spatium, 0.25 * _spatium);
                  break;
            case SA_NONE:
                  break;
            }
      switch(sa2) {
            case SA_STEM: //ec can't be null
                  sp->p2 += ec->stemPosBeam() - ec->pagePos() + ec->stem()->p2();
                  sp->p2 += QPointF(-0.35 * _spatium, 0.25 * _spatium);
                  break;
            case SA_NONE:
                  break;
            }

      //
      // default position:
      //    horizontal: middle of note head
      //    vertical:   _spatium * .4 above/below note head
      //
      //------p1
      bool stemPos = false;   // p1 starts at chord stem side
      if (note1)
            yo = note1->pos().y();
      else if(_up)
            yo = e1->bbox().top();
      else
            yo = e1->bbox().top() + e1->height();
      yo += _spatium * .9 * __up;
      xo = hw * .5;

      if (stem1) { //sc not null
            Beam* beam1 = sc->beam();
            if (beam1 && (beam1->elements().back() != sc) && (sc->up() == _up)) {
                  qreal sh = stem1->height() + _spatium;
                  yo       = sc->downNote()->pos().y() + sh * __up;
                  xo       = stem1->pos().x();
                  stemPos  = true;
                  }
            else {
                  if (sc->up() && _up)
                        xo = hw + _spatium * .3;
                  //
                  // handle case: stem up   - stem down
                  //              stem down - stem up
                  //
                  if ((sc->up() != ecr->up()) && (sc->up() == _up)) {
                        Note* n1  = sc->up() ? sc->downNote() : sc->upNote();
                        Note* n2  = 0;
                        if(ec)
                              n2 = ec->up() ? ec->downNote() : ec->upNote();
                        qreal yd  = (n2?n2->pos().y():e2->pos().y()) - n1->pos().y();

                        yd *= .5;

                        qreal sh = stem1->height();    // limit y move
                        if (yd > 0.0) {
                              if (yd > sh)
                                    yd = sh;
                              }
                        else {
                              if (yd < - sh)
                                    yd = -sh;
                              }
                        stemPos = true;
                        if ((_up && (yd < -_spatium)) || (!_up && (yd > _spatium)))
                              yo += yd;
                        }
                  else if (sc->up() != _up)
                        yo = fixArticulations(yo, sc, __up);
                  }
            }

      if (sa1 == SA_NONE)
            sp->p1 += QPointF(xo, yo);

      //------p2
      xo = hw * .5;
      if (note2)
            yo = note2->pos().y();
      else if(_up)
            yo = e2->bbox().top();
      else
            yo = e2->bbox().top() + e2->height();
      yo += _spatium * .9 * __up;

      if (stem2) { //ec can't be null
            Beam* beam2 = ec->beam();
            if ((stemPos && (scr->up() == ec->up()))
               || (beam2
                 && (!beam2->elements().isEmpty())
                 && (beam2->elements().front() != ec)
                 && (ec->up() == _up)
                 && sc && (sc->noteType() == NOTE_NORMAL)
                 )
                  ) {
                  qreal sh = stem2->height() + _spatium;
                  if (_up)
                        yo = ec->downNote()->pos().y() - sh;
                  else
                        yo = ec->upNote()->pos().y() + sh;
                  xo = stem2->pos().x();
                  }
            else if (!ec->up() && !_up)
                  xo = -_spatium * .3 + note2->x();
            //
            // handle case: stem up   - stem down
            //              stem down - stem up
            //
            if ((scr->up() != ec->up()) && (ec->up() == _up)) {
                  Note* n1 = 0;
                  if(sc)
                        sc->up() ? sc->downNote() : sc->upNote();
                  Note* n2 = ec->up() ? ec->downNote() : ec->upNote();
                  qreal yd = n2->pos().y() - (n1?n1->pos().y():e1->pos().y());

                  yd *= .5;

                  qreal mh = stem2->height();    // limit y move
                  if (yd > 0.0) {
                        if (yd > mh)
                              yd = mh;
                        }
                  else {
                        if (yd < - mh)
                              yd = -mh;
                        }

                  if ((_up && (yd > _spatium)) || (!_up && (yd < -_spatium)))
                        yo -= yd;
                  }
            else if (ec->up() != _up)
                  yo = fixArticulations(yo, ec, __up);
            }

      if (sa2 == SA_NONE)
            sp->p2 += QPointF(xo, yo);
      }