Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c20bda5856
Fetching contributors…

Cannot retrieve contributors at this time

file 153 lines (137 sloc) 5.144 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
//=============================================================================
// MusE Score
// Linux Music Score Editor
// $Id: edittempo.cpp 2649 2010-01-27 23:59:23Z dbolton $
//
// Copyright (C) 2002-2007 Werner Schweer and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================

#include "edittempo.h"

struct TempoVal {
      QString name;
      double bpm;

      TempoVal(const TempoVal& v) {
            name = v.name;
            bpm = v.bpm;
            }
      TempoVal(const char* s, int t) {
            name = QString::fromUtf8(s);
            bpm = t;
            }
      };

static TempoVal tempos[] = {
      TempoVal("Adagio", 72),
      TempoVal("Allegro", 132),
      TempoVal("Allegretto", 120),
      TempoVal("Andante", 96),
      TempoVal("Con brio", 132),
      TempoVal("Con moto", 132),
      TempoVal("Grave", 48),
      TempoVal("Largo", 48),
      TempoVal("Lento", 48),
      TempoVal("Maestoso", 72),
      TempoVal("Moderato", 112),
      TempoVal("Prestissimo", 200),
      TempoVal("Presto", 184),
      TempoVal("Vivace", 144),
      TempoVal("Vivo", 120),
      TempoVal("Ballad", 60),
      TempoVal("Fast", 132),
      TempoVal("Lively", 120),
      TempoVal("Moderate", 112),
      TempoVal("Slow", 60),
      TempoVal("Very slow", 44),
      TempoVal("With movement", 120),
      TempoVal("Entrainant", 120),
      TempoVal("Lent", 60),
      TempoVal("Rapide", 132),
      TempoVal("Regulier", 96),
      TempoVal("Vif", 120),
      TempoVal("Vite", 132),
      TempoVal("Vivement", 176),
      TempoVal("Bewegt", 112),
      TempoVal("Langsam", 60),
      TempoVal("Lebhaft", 120),
      TempoVal("Mäßig", 112), // utf8!
      TempoVal("Schnell", 132)
      };

static bool tempoListInit = true;
static bool tempoListChanged = true;

static QList<TempoVal*> tempoL;

//---------------------------------------------------------
// EditTempo
//---------------------------------------------------------

EditTempo::EditTempo(QWidget* parent)
   : QDialog(parent)
      {
      setupUi(this);
      if (tempoListInit) {
            tempoListInit = false;
            for (unsigned i = 0; i < sizeof(tempos)/sizeof(*tempos); ++i) {
                  tempoL.append(new TempoVal(tempos[i]));
                  }
            }
      int idx = 0;
      foreach(TempoVal* v, tempoL) {
            QListWidgetItem* item = new QListWidgetItem(v->name, tempoList);
            item->setData(Qt::UserRole, idx++);
            }
      selectTempo(3);
      connect(tempoText, SIGNAL(textChanged(const QString&)), SLOT(textChanged(const QString&)));
      connect(tempoBPM, SIGNAL(valueChanged(double)), SLOT(bpmChanged(double)));
      connect(tempoList, SIGNAL(currentRowChanged(int)), SLOT(selectTempo(int)));
      connect(tempoList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(itemDoubleClicked(QListWidgetItem*)));
      }

//---------------------------------------------------------
// itemDoubleClicked
//---------------------------------------------------------

void EditTempo::itemDoubleClicked(QListWidgetItem* item)
      {
      int idx = item->data(Qt::UserRole).toInt();
      selectTempo(idx);
      accept();
      }

//---------------------------------------------------------
// selectTempo
//---------------------------------------------------------

void EditTempo::selectTempo(int n)
      {
      if (n < 0 || n >= tempoL.size())
            return;
      _text = tempoL[n]->name;
      tempoText->setText(_text);
      _bpm = tempoL[n]->bpm;
      tempoBPM->setValue(_bpm);
      }

//---------------------------------------------------------
// textChanged
//---------------------------------------------------------

void EditTempo::textChanged(const QString& s)
      {
      _text = s;
      int idx = tempoList->currentItem()->data(Qt::UserRole).toInt();
      tempoL[idx]->name = s;
      tempoListChanged = true;
      tempoList->currentItem()->setText(s);
      }

//---------------------------------------------------------
// bpmChanged
//---------------------------------------------------------

void EditTempo::bpmChanged(double v)
      {
      _bpm = v;
      int idx = tempoList->currentItem()->data(Qt::UserRole).toInt();
      tempoL[idx]->bpm = v;
      tempoListChanged = true;
      }
Something went wrong with that request. Please try again.