Example #1
0
void Clef::layout()
      {
      // determine current number of lines and line distance
      int lines      = 5;                       // assume a resonable default
      qreal lineDist = 1.0;

      StaffType* staffType;
      if (staff() && staff()->staffType()) {
            staffType = staff()->staffType();
            if (!staffType->genClef()) {        // if no clef, set empty bbox and do nothing
                  setbbox(QRectF());
                  return;
                  }

            // tablatures:
            if (staffType->group() == TAB_STAFF) {
                  // if current clef type not compatible with tablature,
                  // set tab clef according to score style
                  if (clefTable[clefType()].staffGroup != TAB_STAFF)
                        setClefType( ClefType(score()->styleI(ST_tabClef)) );
                  }
            // all staff types: init values from staff type
            lines = staffType->lines();
            lineDist = staffType->lineDistance().val();
            }

      // if nothing changed since last layout, do nothing
      if (curClefType == clefType() && curLines == lines && curLineDist == lineDist)
            return;
      // if something has changed, cache new values and re-layout
      curClefType = clefType();
      curLines    = lines;
      curLineDist = lineDist;
      layout1();
      }
Example #2
0
ClefType ClefInfo::tag2type(const QString& s)
      {
      for (unsigned i = 0; i < sizeof(ClefInfo::clefTable)/sizeof(*ClefInfo::clefTable); ++i) {
            if (clefTable[i]._tag == s)
                  return ClefType(i);
            }
      return ClefType::G;
      }
Example #3
0
void MuseScore::clefMenu()
      {
      if (clefPalette == 0) {
            Palette* sp = new Palette;
            sp->setGrid(60, 80);
            sp->resize(360, 400);
            clefPalette = new PaletteScrollArea(sp);
            clefPalette->setRestrictHeight(false);
            clefPalette->setWindowTitle(tr("MuseScore: Clefs"));
            for (int i = 0; i < CLEF_MAX; ++i) {
                  Clef* k = new ::Clef(gscore);
                  k->setClefType(ClefType(i));
                  sp->append(k, qApp->translate("clefTable", clefTable[i].name));
                  }
            }
      clefPalette->show();
      clefPalette->raise();
      }
Example #4
0
void InstrumentTemplate::read(const QDomElement& de)
      {
      bool customDrumset = false;
      staves = 1;
      for (int i = 0; i < MAX_STAVES; ++i) {
            clefIdx[i]     = CLEF_INVALID;
            staffLines[i]  = -1;
            smallStaff[i]  = false;
            bracket[i]     = NO_BRACKET;
            bracketSpan[i] = 0;
            barlineSpan[i] = 0;
            }
      minPitchA  = 0;
      maxPitchA  = 127;
      minPitchP  = 0;
      maxPitchP  = 127;
      transpose.diatonic  = 0;
      transpose.chromatic  = 0;
      useDrumset = false;

      for (QDomElement e = de.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
            const QString& tag(e.tagName());
            const QString& val(e.text());

            if (tag == "name" || tag == "longName") {               // "name" is obsolete
                  int pos = e.attribute("pos", "0").toInt();
                  QString longName = Xml::htmlToString(e);
                  longNames.append(StaffName(longName, pos));
                  }
            else if (tag == "short-name" || tag == "shortName") {   // "short-name" is obsolete
                  int pos = e.attribute("pos", "0").toInt();
                  QString shortName = Xml::htmlToString(e);
                  shortNames.append(StaffName(shortName, pos));
                  }
            else if (tag == "description")
                  trackName = val;
            else if (tag == "extended")
                  extended = true;
            else if (tag == "staves") {
                  staves = val.toInt();
                  bracketSpan[0] = staves;
                  barlineSpan[0] = staves;
                  }
            else if (tag == "clef") {
                  int idx = readStaffIdx(e);
                  bool ok;
                  int i = val.toInt(&ok);
                  if (!ok) {
                        ClefType ct = Clef::clefType(val);
                        clefIdx[idx] = ct;
                        }
                  else
                        clefIdx[idx] = ClefType(i);
                  }
            else if (tag == "stafflines") {
                  int idx = readStaffIdx(e);
                  staffLines[idx] = val.toInt();
                  }
            else if (tag == "smallStaff") {
                  int idx = readStaffIdx(e);
                  smallStaff[idx] = val.toInt();
                  }
            else if (tag == "bracket") {
                  int idx = readStaffIdx(e);
                  bracket[idx] = BracketType(val.toInt());
                  }
            else if (tag == "bracketSpan") {
                  int idx = readStaffIdx(e);
                  bracketSpan[idx] = val.toInt();
                  }
            else if (tag == "barlineSpan") {
                  int idx = readStaffIdx(e);
                  barlineSpan[idx] = val.toInt();
                  }
            else if (tag == "Tablature") {
                  tablature = new Tablature;
                  tablature->read(e);
                  }
            else if (tag == "aPitchRange")
                  setPitchRange(val, &minPitchA, &maxPitchA);
            else if (tag == "pPitchRange")
                  setPitchRange(val, &minPitchP, &maxPitchP);
            else if (tag == "transposition") {    // obsolete
                  transpose.chromatic = val.toInt();
                  transpose.diatonic = chromatic2diatonic(val.toInt());
                  }
            else if (tag == "transposeChromatic")
                  transpose.chromatic = val.toInt();
            else if (tag == "transposeDiatonic")
                  transpose.diatonic = val.toInt();
            else if (tag == "drumset")
                  useDrumset = val.toInt();
            else if (tag == "Drum") {
                  // if we see on of this tags, a custom drumset will
                  // be created
                  if (drumset == 0)
                        drumset = new Drumset(*smDrumset);
                  if (!customDrumset) {
                        drumset->clear();
                        customDrumset = true;
                        }
                  drumset->load(e);
                  }
            else if (tag == "MidiAction") {
                  NamedEventList a;
                  a.read(e);
                  midiActions.append(a);
                  }
            else if (tag == "channel") {
                  Channel a;
                  a.read(e);
                  channel.append(a);
                  }
            else if (tag == "Articulation") {
                  MidiArticulation a;
                  a.read(e);
                  int n = articulation.size();
                  int i;
                  for(i = 0; i < n; ++i) {
                        if (articulation[i].name == a.name) {
                              articulation[i] = a;
                              break;
                              }
                        }
                  if (i == n)
                        articulation.append(a);
                  }
            else if (tag == "stafftype") {
                  if (val == "tablature")
                        useTablature = true;
                  else {
                        qDebug("unknown stafftype <%s>\n", qPrintable(val));
                        domError(e);
                        }
                  }
            else if (tag == "init") {
                  InstrumentTemplate* ttt = searchTemplate(val);
                  if (ttt) {
// qDebug("Instrument template init <%s> from <%s>\n", qPrintable(trackName), qPrintable(ttt->trackName));
                        init(*ttt);
                        }
                  else
                        qDebug("Instrument template <%s> not found\n", qPrintable(val));
                  }
            else
                  domError(e);
            }
      //
      // check bar line spans
      //
      int barLine = 0;
      for (int i = 0; i < staves; ++i) {
            int bls = barlineSpan[i];
            if (barLine) {
                  if (bls)
                        barlineSpan[i] = 0;
                  }
            else {
                  if (bls == 0) {
                        bls = 1;
                        barlineSpan[i] = 1;
                        }
                  barLine = bls;
                  }
            --barLine;
            }
      for (int i = 0; i < MAX_STAVES; ++i) {
            if (clefIdx[i] == CLEF_INVALID)
                  clefIdx[i] = CLEF_G;
            if (staffLines[i] == -1)
                  staffLines[i] = 5;
            }
      if (channel.isEmpty()) {
            Channel a;
            a.chorus       = 0;
            a.reverb       = 0;
            a.name         = "normal";
            a.program      = 0;
            a.bank         = 0;
            a.volume       = 100;
            a.pan         = 60;
            channel.append(a);
            }
      if (useDrumset) {
            if (channel[0].bank == 0)
                  channel[0].bank = 128;
            channel[0].updateInitList();
            }
      if (trackName.isEmpty() && !longNames.isEmpty())
            trackName = parseInstrName(longNames[0].name);
      }
Example #5
0
void Clef::layout()
      {
      if (curClefType == clefType())
            return;

      qreal smag     = _small ? score()->style(ST_smallClefMag).toDouble() : 1.0;
      qreal _spatium = spatium();
      qreal msp      = _spatium * smag;
      qreal yoff     = 0.0;

      qDeleteAll(elements);
      elements.clear();

      curClefType    = clefType();
      int lines      = 5;
      qreal lineDist = 1.0;
#if 0       // TODO: does not work with caching of curClefType
      if (staff() && staff()->staffType()) {
            StaffType* staffType = staff()->staffType();

            if (staffType->group() == TAB_STAFF) {
                  if (!staffType->genClef())
                        return;
                  if (clefTable[st].staffGroup != TAB_STAFF)
                        st = ClefType(score()->styleI(ST_tabClef));
	            }
            lines = staffType->lines();
            lineDist = staffType->lineDistance().val();
	      }
#endif
      Symbol* symbol = new Symbol(score());

      switch (curClefType) {
            case CLEF_G:
                  symbol->setSym(trebleclefSym);
                  yoff = 3.0;
                  break;
            case CLEF_G1:
                  {
                  symbol->setSym(trebleclefSym);
                  yoff = 3.0;
                  Symbol* number = new Symbol(score());
                  number->setMag(smag);
                  number->setSym(clefEightSym);
                  addElement(number, 1.0 * msp, -5.0 * msp + yoff * _spatium);
                  }
                  break;
            case CLEF_G2:
                  {
                  symbol->setSym(trebleclefSym);
                  yoff = 3.0;
                  Symbol* number = new Symbol(score());
                  symbol->setMag(smag);
                  number->setSym(clefOneSym);
                  addElement(number, .6 * msp, -5.0 * msp + yoff * _spatium);
                  number = new Symbol(score());
                  number->setSym(clefFiveSym);
                  addElement(number, 1.4 * msp, -5.0 * msp + yoff * _spatium);
                  }
                  break;
            case CLEF_G3:
                  {
                  symbol->setSym(trebleclefSym);
                  yoff = 3.0;
                  Symbol* number = new Symbol(score());
                  symbol->setMag(smag);
                  number->setSym(clefEightSym);
                  addElement(number, 1.0 * msp, 4.0 * msp + yoff * _spatium);
                  }
                  break;
            case CLEF_F:
                  symbol->setSym(bassclefSym);
                  yoff = 1.0;
                  break;
            case CLEF_F8:
                  {
                  symbol->setSym(bassclefSym);
                  yoff = 1.0;
                  Symbol* number = new Symbol(score());
                  symbol->setMag(smag);
                  number->setSym(clefEightSym);
                  addElement(number, .0, 4.5 * msp + yoff * _spatium);
                  }
                  break;
            case CLEF_F15:
                  {
                  symbol->setSym(bassclefSym);
                  yoff = 1.0;
                  Symbol* number = new Symbol(score());
                  symbol->setMag(smag);
                  number->setSym(clefOneSym);
                  addElement(number, .0, 4.5 * msp + yoff * _spatium);
                  number = new Symbol(score());
                  number->setSym(clefFiveSym);
                  addElement(number, .8 * msp, 4.5 * msp + yoff * _spatium);
                  }
                  break;
            case CLEF_F_B:                            // baritone clef
                  symbol->setSym(bassclefSym);
                  yoff = 2.0;
                  break;
            case CLEF_F_C:                            // subbass clef
                  symbol->setSym(bassclefSym);
                  yoff = 0.0;
                  break;
            case CLEF_C1:
                  symbol->setSym(altoclefSym);
                  yoff = 4.0;
                  break;
            case CLEF_C2:
                  symbol->setSym(altoclefSym);
                  yoff = 3.0;
                  break;
            case CLEF_C3:
                  symbol->setSym(altoclefSym);
                  yoff = 2.0;
                  break;
            case CLEF_C4:
                  symbol->setSym(altoclefSym);
                  yoff = 1.0;
                  break;
            case CLEF_C5:
                  symbol->setSym(altoclefSym);
                  yoff = 0.0;
                  break;
            case CLEF_TAB:
                  symbol->setSym(tabclefSym);
                  // on tablature, position clef at half the number of spaces * line distance
                  yoff = lineDist * (lines - 1) * .5;
                  break;
            case CLEF_TAB2:
                  symbol->setSym(tabclef2Sym);
                  // on tablature, position clef at half the number of spaces * line distance
                  yoff = lineDist * (lines - 1) * .5;
                  break;
            case CLEF_PERC:
            case CLEF_PERC2:
                  symbol->setSym(percussionclefSym);
                  yoff = lineDist * (lines - 1) * 0.5;
                  break;
            case CLEF_G4:
                  symbol->setSym(trebleclefSym);
                  yoff = 4.0;
                  break;
            case CLEF_F_8VA:
                  {
                  symbol->setSym(bassclefSym);
                  yoff = 1.0;
                  Symbol* number = new Symbol(score());
                  number->setMag(smag);
                  number->setSym(clefEightSym);
                  addElement(number, .5 * msp, -1.5 * msp + yoff * _spatium);
                  }
                  break;
            case CLEF_F_15MA:
                  {
                  symbol->setSym(bassclefSym);
                  yoff = 1.0;
                  Symbol* number = new Symbol(score());
                  symbol->setMag(smag);
                  number->setSym(clefOneSym);
                  addElement(number, .0 * msp, -1.5 * msp + yoff * _spatium);
                  number = new Symbol(score());
                  number->setSym(clefFiveSym);
                  addElement(number, .8 * msp, -1.5 * msp + yoff * _spatium);
                  }
                  break;
            case CLEF_INVALID:
            case CLEF_MAX:
                  return;
            }
      symbol->setMag(smag * mag());
      symbol->layout();
      addElement(symbol, .0, yoff * _spatium);
      setbbox(QRectF());
      for (iElement i = elements.begin(); i != elements.end(); ++i) {
            Element* e = *i;
            e->setColor(curColor());
            addbbox(e->bbox().translated(e->pos()));
            e->setSelected(selected());
            }
      }
Example #6
0
void Clef::layout()
      {
      // determine current number of lines and line distance
      int   lines       = 5;              // assume resonable defaults
      qreal lineDist    = 1.0;

      Staff*      stf         = staff();
      StaffType*  staffType   = nullptr;
      Segment*    clefSeg     = static_cast<Segment*>(parent());
      // check clef visibility and type compatibility
      if (clefSeg && stf && stf->staffType()) {
            bool        bHide;
            // check staff type allows clef display
            staffType = staff()->staffType();
#if 0 // <<<<<<< HEAD
            if (!staffType->genClef()) {        // if no clef, set empty bbox and do nothing
                  qDeleteAll(elements);
                  elements.clear();
                  setbbox(QRectF());
                  return;
                  }

            // tablatures:
            if (staffType->group() == StaffGroup::TAB) {
                  // if current clef type not compatible with tablature,
                  // set tab clef according to score style
                  if (ClefInfo::staffGroup(clefType()) != StaffGroup::TAB)
                        setClefType( ClefType(score()->styleI(StyleIdx::tabClef)) );
#else
            bHide = !staffType->genClef();

            // check clef is compatible with staff type group
            int tick = clefSeg->tick();
            if (ClefInfo::staffGroup(clefType()) != staffType->group()) {
                  if (tick > 0 && !generated()) // if clef is not generated, hide it
                        bHide = true;
                  else                          // if generated, replace with initial clef type
                        // TODO : instead of initial staff clef (which is assumed to be compatible)
                        // use the last compatible clef previously found in staff
                        _clefTypes = stf->clefTypeList(0);
#endif      // >>>>>>> 38c666fa91f5bdaaa6d9ca0645c437c799be8c79
                  }

            //
            // courtesy clef
            //
            bool showClef = true;
#if 0 // <<<<<<< HEAD
            Segment* clefSeg = static_cast<Segment*>(parent());
            if (clefSeg) {
                  int tick = clefSeg->tick();
                  // only if there is a clef change
                  if (stf->clef(tick) != stf->clef(tick-1)) {
                        // locate clef at the begining of next measure, if any
                        Clef*       clefNext    = nullptr;
                        Segment*    clefSegNext = nullptr;
                        Measure*    meas        = static_cast<Measure*>(clefSeg->parent());
                        Measure*    measNext    = meas->nextMeasure();
                        if (measNext) {
                              clefSegNext = measNext->findSegment(SegmentType::Clef, tick);
                              if (clefSegNext)
                                    clefNext = static_cast<Clef*>(clefSegNext->element(track()));
                              }
                        // show this clef if: it is not a courtesy clef (no next clef or not at the end of the measure)
                        showClef = !clefNext || (clefSeg->tick() != meas->tick() + meas->ticks())
                              // if courtesy clef: show if score has courtesy clefs on
                              || ( score()->styleB(StyleIdx::genCourtesyClef)
                              // AND measure is not at the end of a repeat or of a section
                              && !( (meas->repeatFlags() & Repeat::END) || meas->sectionBreak() )
                              // AND this clef has courtesy clef turned on
                              && showCourtesy() );
                        if (!showClef)    {     // if no clef, set empty bbox and do nothing
                              qDeleteAll(elements);
                              elements.clear();
                              setbbox(QRectF());
                              return;
                              }
#else
            // only if there is a clef change
            if (!bHide && tick > 0 && stf->clef(tick) != stf->clef(tick-1)) {
                  // locate clef at the begining of next measure, if any
                  Clef*       clefNext    = nullptr;
                  Segment*    clefSegNext = nullptr;
                  Measure*    meas        = static_cast<Measure*>(clefSeg->parent());
                  Measure*    measNext    = meas->nextMeasure();
                  if (measNext) {
                        clefSegNext = measNext->findSegment(SegmentType::Clef, tick);
                        if (clefSegNext)
                              clefNext = static_cast<Clef*>(clefSegNext->element(track()));
#endif      // >>>>>>> 38c666fa91f5bdaaa6d9ca0645c437c799be8c79
                        }
                  // show this clef if: it is not a courtesy clef (no next clef or not at the end of the measure)
                  showClef = !clefNext || (clefSeg->tick() != meas->tick() + meas->ticks())
                        // if courtesy clef: show if score has courtesy clefs on
                        || ( score()->styleB(StyleIdx::genCourtesyClef)
                        // AND measure is not at the end of a repeat or of a section
                        && !( (meas->repeatFlags() & Repeat::END) || meas->sectionBreak() )
                        // AND this clef has courtesy clef turned on
                        && showCourtesy() );
                  bHide |= !showClef;
                  }

            // if clef not to show or not compatible with staff group
            if (bHide) {
                  qDeleteAll(elements);         // set empty bbox and do nothing
                  elements.clear();
                  setbbox(QRectF());
                  return;
                  }

            lines = staffType->lines();         // init values from staff type
            lineDist = staffType->lineDistance().val();
            }

      // if nothing changed since last layout, do nothing
//DEBUG      if (curClefType == clefType() && curLines == lines && curLineDist == lineDist)
//            return;
      // if something has changed, cache new values and re-layout
      curClefType = clefType();
      curLines    = lines;
      curLineDist = lineDist;
      layout1();
      }

//---------------------------------------------------------
//   layout1
//---------------------------------------------------------

void Clef::layout1()
      {
      qreal smag     = mag();
      qreal _spatium = spatium();
      // qreal msp      = score()->spatium() * smag;
      qreal yoff     = 0.0;

      qDeleteAll(elements);
      elements.clear();

      Symbol* symbol = new Symbol(score());

      switch (curClefType) {
            case ClefType::G:                              // G clef on 2nd line
                  symbol->setSym(SymId::gClef);
                  yoff = 3.0 * curLineDist;
                  break;
            case ClefType::G1:                             // G clef 8va on 2nd line
                  symbol->setSym(SymId::gClef8va);
                  yoff = 3.0 * curLineDist;
                  break;
            case ClefType::G2:                             // G clef 15ma on 2nd line
                  symbol->setSym(SymId::gClef15ma);
                  yoff = 3.0 * curLineDist;
                  break;
            case ClefType::G3:                             // G clef 8vb on 2nd line
                  symbol->setSym(SymId::gClef8vb);
                  yoff = 3.0 * curLineDist;
                  break;
            case ClefType::F:                              // F clef on penultimate line
                  symbol->setSym(SymId::fClef);
                  yoff = 1.0 * curLineDist;
                  break;
            case ClefType::F8:                             // F clef 8va bassa on penultimate line
                  symbol->setSym(SymId::fClef8vb);
                  yoff = 1.0 * curLineDist;
                  break;
            case ClefType::F15:                            // F clef 15ma bassa on penultimate line
                  symbol->setSym(SymId::fClef15mb);
                  yoff = 1.0 * curLineDist;
                  break;
            case ClefType::F_B:                            // baritone clef
                  symbol->setSym(SymId::fClef);
                  yoff = 2.0 * curLineDist;
                  break;
            case ClefType::F_C:                            // subbass clef
                  symbol->setSym(SymId::fClef);
                  yoff = 0.0;
                  break;
            case ClefType::C1:                             // C clef in 1st line
                  symbol->setSym(SymId::cClef);
                  yoff = 4.0 * curLineDist;
                  break;
            case ClefType::C2:                             // C clef on 2nd line
                  symbol->setSym(SymId::cClef);
                  yoff = 3.0 * curLineDist;
                  break;
            case ClefType::C3:                             // C clef in 3rd line
                  symbol->setSym(SymId::cClef);
                  yoff = 2.0 * curLineDist;
                  break;
            case ClefType::C4:                             // C clef on 4th line
                  symbol->setSym(SymId::cClef);
                  yoff = 1.0 * curLineDist;
                  break;
            case ClefType::C5:                             // C clef on 5th line
                  symbol->setSym(SymId::cClef);
                  yoff = 0.0;
                  break;
            case ClefType::TAB:                            // TAB clef
                  symbol->setSym(SymId::sixStringTabClef);
                  // on tablature, position clef at half the number of spaces * line distance
                  yoff = curLineDist * (curLines - 1) * .5;
                  break;
            case ClefType::TAB2:                           // TAB clef alternate style
                  symbol->setSym(SymId::sixStringTabClefSerif);
                  // on tablature, position clef at half the number of spaces * line distance
                  yoff = curLineDist * (curLines - 1) * .5;
                  break;
            case ClefType::PERC:                           // percussion clefs
            case ClefType::PERC2:         // no longer supported: fall back to same glyph as PERC
                  symbol->setSym(SymId::unpitchedPercussionClef1);
                  yoff = curLineDist * (curLines - 1) * 0.5;
                  break;
            case ClefType::G4:                             // G clef in 1st line
                  symbol->setSym(SymId::gClef);
                  yoff = 4.0 * curLineDist;
                  break;
            case ClefType::F_8VA:                          // F clef 8va on penultimate line
                  symbol->setSym(SymId::fClef8va);
                  yoff = 1.0 * curLineDist;
                  break;
            case ClefType::F_15MA:                         // F clef 15ma on penultimate line
                  symbol->setSym(SymId::fClef15ma);
                  yoff = 1.0 * curLineDist;
                  break;
            case ClefType::INVALID:
            case ClefType::MAX:
                  return;
            }

      symbol->setMag(smag);
      symbol->layout();
      addElement(symbol, .0, yoff * _spatium);
      setbbox(QRectF());
      for (auto i = elements.begin(); i != elements.end(); ++i) {
            Element* e = *i;
            e->setColor(curColor());
            addbbox(e->bbox().translated(e->pos()));
            e->setSelected(selected());
            }
      }

//---------------------------------------------------------
//   draw
//---------------------------------------------------------

void Clef::draw(QPainter* painter) const
      {
      if (staff() && !staff()->staffType()->genClef())
            return;
      QColor color(curColor());
      foreach(Element* e, elements) {
            e->setColor(color);
            QPointF pt(e->pos());
            painter->translate(pt);
            e->draw(painter);
            painter->translate(-pt);
            }
      }