Palette* MuseScore::newTempoPalette() { Palette* sp = new Palette; sp->setName(QT_TRANSLATE_NOOP("Palette", "Tempo")); sp->setMag(0.65); sp->setGrid(60, 30); sp->setDrawGrid(true); static const TempoPattern tp[] = { TempoPattern("<sym>metNoteHalfUp</sym> = 80", 80.0/30.0), // 1/2 TempoPattern("<sym>metNoteQuarterUp</sym> = 80", 80.0/60.0), // 1/4 TempoPattern("<sym>metNote8thUp</sym> = 80", 80.0/120.0), // 1/8 TempoPattern("<sym>metNoteHalfUp</sym><sym>space</sym><sym>metAugmentationDot</sym> = 80", 120/30.0), // dotted 1/2 TempoPattern("<sym>metNoteQuarterUp</sym><sym>space</sym><sym>metAugmentationDot</sym> = 80", 120/60.0), // dotted 1/4 TempoPattern("<sym>metNote8thUp</sym><sym>space</sym><sym>metAugmentationDot</sym> = 80", 120/120.0), // dotted 1/8 }; for (unsigned i = 0; i < sizeof(tp)/sizeof(*tp); ++i) { TempoText* tt = new TempoText(gscore); tt->setFollowText(true); // leave track at default (-1) to make it possible // for drop() to tell that this came from palette // (it will then be set to 0 there) //tt->setTrack(0); tt->setTempo(tp[i].f); tt->setXmlText(tp[i].pattern); sp->append(tt, tr("Tempo text"), QString(), 1.5); } return sp; }
void setTempoToScore(Score *score, int tick, double beatsPerSecond) { if (score->tempomap()->find(tick) != score->tempomap()->end()) return; // don't repeat tempo, always set only tempo for tick 0 if (tick > 0 && score->tempo(tick) == beatsPerSecond) return; score->setTempo(tick, beatsPerSecond); auto *data = preferences.midiImportOperations.data(); if (data->trackOpers.showTempoText.value()) { const int tempoInBpm = qRound(beatsPerSecond * 60.0); TempoText *tempoText = new TempoText(score); tempoText->setTempo(beatsPerSecond); tempoText->setXmlText(QString("<sym>metNoteQuarterUp</sym> = %1").arg(tempoInBpm)); tempoText->setTrack(0); Measure *measure = score->tick2measure(tick); if (!measure) { qDebug("MidiTempo::setTempoToScore: no measure for tick %d", tick); return; } Segment *segment = measure->getSegment(Segment::Type::ChordRest, tick); if (!segment) { qDebug("MidiTempo::setTempoToScore: no chord/rest segment for tempo at %d", tick); return; } segment->add(tempoText); data->hasTempoText = true; // to show tempo text column in the MIDI import panel } }
void MuseScore::addTempo() { ChordRest* cr = cs->getSelectedChordRest(); if (!cr) return; // double bps = 2.0; SigEvent event = cs->sigmap()->timesig(cr->tick()); Fraction f = event.nominal(); QString text("<sym>metNoteQuarterUp</sym> = 80"); switch (f.denominator()) { case 1: text = "<sym>metNoteWhole</sym> = 80"; break; case 2: text = "<sym>metNoteHalfUp</sym> = 80"; break; case 4: text = "<sym>metNoteQuarterUp</sym> = 80"; break; case 8: if(f.numerator() % 3 == 0) text = "<sym>metNoteQuarterUp</sym><sym>space</sym><sym>metAugmentationDot</sym> = 80"; else text = "<sym>metNote8thUp</sym> = 80"; break; case 16: if(f.numerator() % 3 == 0) text = "<sym>metNote8thUp</sym><sym>space</sym><sym>metAugmentationDot</sym> = 80"; else text = "<sym>metNote16thUp</sym> = 80"; break; case 32: if(f.numerator() % 3 == 0) text = "<sym>metNote16thUp</sym><sym>space</sym><sym>metAugmentationDot</sym> = 80"; else text = "<sym>metNote32ndUp</sym> = 80"; break; case 64: if(f.numerator() % 3 == 0) text = "<sym>metNote32ndUp</sym><sym>space</sym><sym>metAugmentationDot</sym> = 80"; else text = "<sym>metNote64thUp</sym> = 80"; break; default: break; } TempoText* tt = new TempoText(cs); tt->setParent(cr->segment()); tt->setTrack(0); tt->setXmlText(text); tt->setFollowText(true); //tt->setTempo(bps); cs->undoAddElement(tt); cv->startEdit(tt); }