~ubuntu-branches/ubuntu/trusty/muse/trusty

« back to all changes in this revision

Viewing changes to muse/arranger/arranger.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2013-08-28 16:25:57 UTC
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: package-import@ubuntu.com-20130828162557-knls3ip7j262eepx
Tags: upstream-2.1.2
ImportĀ upstreamĀ versionĀ 2.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include <stdio.h>
26
26
#include <limits.h>
 
27
#include <math.h>
27
28
 
28
29
#include <QComboBox>
29
30
#include <QGridLayout>
77
78
std::vector<Arranger::custom_col_t> Arranger::custom_columns;     //FINDMICH TODO: eliminate all usage of new_custom_columns
78
79
std::vector<Arranger::custom_col_t> Arranger::new_custom_columns; //and instead let the arranger update without restarting muse!
79
80
QByteArray Arranger::header_state;
 
81
static const char* gArrangerRasterStrings[] = {
 
82
      QT_TRANSLATE_NOOP("MusEGui::Arranger", "Off"), QT_TRANSLATE_NOOP("MusEGui::Arranger", "Bar"), "1/2", "1/4", "1/8", "1/16"
 
83
      };
 
84
static int gArrangerRasterTable[] = { 1, 0, 768, 384, 192, 96 };
80
85
 
81
86
void Arranger::writeCustomColumns(int level, MusECore::Xml& xml)
82
87
{
238
243
      cursorPos->setFixedHeight(22);
239
244
      toolbar->addWidget(cursorPos);
240
245
 
241
 
      const char* rastval[] = {
242
 
            QT_TRANSLATE_NOOP("MusEGui::Arranger", "Off"), QT_TRANSLATE_NOOP("MusEGui::Arranger", "Bar"), "1/2", "1/4", "1/8", "1/16"
243
 
            };
244
246
      label = new QLabel(tr("Snap"));
245
247
      label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
246
248
      label->setIndent(3);
247
249
      toolbar->addWidget(label);
248
 
      QComboBox* raster = new QComboBox();
 
250
      _rasterCombo = new QComboBox();
249
251
      for (int i = 0; i < 6; i++)
250
 
            raster->insertItem(i, tr(rastval[i]));
251
 
      raster->setCurrentIndex(1);
 
252
            _rasterCombo->insertItem(i, tr(gArrangerRasterStrings[i]), gArrangerRasterTable[i]);
 
253
      _rasterCombo->setCurrentIndex(1);
252
254
      // Set the audio record part snapping. Set to 0 (bar), the same as this combo box intial raster.
253
255
      MusEGlobal::song->setArrangerRaster(0);
254
 
      toolbar->addWidget(raster);
255
 
      connect(raster, SIGNAL(activated(int)), SLOT(_setRaster(int)));
256
 
      raster->setFocusPolicy(Qt::TabFocus);
 
256
      toolbar->addWidget(_rasterCombo);
 
257
      connect(_rasterCombo, SIGNAL(activated(int)), SLOT(rasterChanged(int)));
 
258
      _rasterCombo->setFocusPolicy(Qt::TabFocus);
257
259
 
258
260
      // Song len
259
261
      label = new QLabel(tr("Len"));
477
479
      connect(list, SIGNAL(keyPressExt(QKeyEvent*)), canvas, SLOT(redirKeypress(QKeyEvent*)));
478
480
      connect(canvas, SIGNAL(selectTrackAbove()), list, SLOT(selectTrackAbove()));
479
481
      connect(canvas, SIGNAL(selectTrackBelow()), list, SLOT(selectTrackBelow()));
480
 
      connect(canvas, SIGNAL(horizontalZoom(bool,int)), SLOT(horizontalZoom(bool,int)));
 
482
      connect(canvas, SIGNAL(horizontalZoom(bool, const QPoint&)), SLOT(horizontalZoom(bool, const QPoint&)));
 
483
      connect(canvas, SIGNAL(horizontalZoom(int, const QPoint&)), SLOT(horizontalZoom(int, const QPoint&)));
481
484
      connect(lenEntry,           SIGNAL(returnPressed()), SLOT(focusCanvas()));
482
485
      connect(lenEntry,           SIGNAL(escapePressed()), SLOT(focusCanvas()));
483
486
      connect(globalPitchSpinBox, SIGNAL(returnPressed()), SLOT(focusCanvas()));
732
735
void Arranger::writeStatus(int level, MusECore::Xml& xml)
733
736
      {
734
737
      xml.tag(level++, "arranger");
 
738
      xml.intTag(level, "raster", _raster);
735
739
      xml.intTag(level, "info", ib->isChecked());
736
740
      split->writeStatus(level, xml);
737
741
 
785
789
 
786
790
void Arranger::readStatus(MusECore::Xml& xml)
787
791
      {
 
792
      int rast = -1;  
788
793
      for (;;) {
789
794
            MusECore::Xml::Token token(xml.parse());
790
795
            const QString& tag(xml.s1());
793
798
                  case MusECore::Xml::End:
794
799
                        return;
795
800
                  case MusECore::Xml::TagStart:
796
 
                        if (tag == "info")
 
801
                        if (tag == "raster")
 
802
                              rast = xml.parseInt();
 
803
                        else if (tag == "info")
797
804
                              showTrackinfoFlag = xml.parseInt();
798
805
                        else if (tag == split->objectName())
799
806
                              split->readStatus(xml);
811
818
                  case MusECore::Xml::TagEnd:
812
819
                        if (tag == "arranger") {
813
820
                              ib->setChecked(showTrackinfoFlag);
 
821
                              if(rast != -1)
 
822
                                setRasterVal(rast);
814
823
                              return;
815
824
                              }
816
825
                  default:
820
829
      }
821
830
 
822
831
//---------------------------------------------------------
823
 
//   setRaster
 
832
//   rasterChanged
824
833
//---------------------------------------------------------
825
834
 
826
 
void Arranger::_setRaster(int index)
 
835
void Arranger::rasterChanged(int index)
827
836
      {
828
 
      static int rasterTable[] = {
829
 
            1, 0, 768, 384, 192, 96
830
 
            };
831
 
      _raster = rasterTable[index];
 
837
      _raster = gArrangerRasterTable[index];
832
838
      // Set the audio record part snapping.
833
839
      MusEGlobal::song->setArrangerRaster(_raster);
834
840
      canvas->redraw();
836
842
      }
837
843
 
838
844
//---------------------------------------------------------
 
845
//   setRasterVal
 
846
//---------------------------------------------------------
 
847
 
 
848
bool Arranger::setRasterVal(int val)
 
849
{
 
850
  if(_raster == val)
 
851
    return true;
 
852
  int idx = _rasterCombo->findData(val);
 
853
  if(idx == -1)
 
854
  {
 
855
    fprintf(stderr, "Arranger::setRasterVal raster:%d not found\n", val);
 
856
    return false;
 
857
  }
 
858
  _raster = val;
 
859
  _rasterCombo->blockSignals(true);
 
860
  _rasterCombo->setCurrentIndex(idx);
 
861
  _rasterCombo->blockSignals(false);
 
862
  // Set the audio record part snapping.
 
863
  MusEGlobal::song->setArrangerRaster(_raster);
 
864
  canvas->redraw();
 
865
  return true;
 
866
}
 
867
 
 
868
//---------------------------------------------------------
839
869
//   reset
840
870
//---------------------------------------------------------
841
871
 
1207
1237
        key+= Qt::CTRL;
1208
1238
 
1209
1239
  if (key == shortcuts[SHRT_ZOOM_IN].key) {
1210
 
        int offset = 0;
1211
 
        QPoint cp = canvas->mapFromGlobal(QCursor::pos());
1212
 
        QPoint sp = editor->mapFromGlobal(QCursor::pos());
1213
 
        if(cp.x() >= 0 && cp.x() < canvas->width() && sp.y() >= 0 && sp.y() < editor->height())
1214
 
          offset = cp.x();
1215
 
        horizontalZoom(true, offset);  
 
1240
        horizontalZoom(true, QCursor::pos());
1216
1241
        return;
1217
1242
        }
1218
1243
  else if (key == shortcuts[SHRT_ZOOM_OUT].key) {
1219
 
        int offset = 0;
1220
 
        QPoint cp = canvas->mapFromGlobal(QCursor::pos());
1221
 
        QPoint sp = editor->mapFromGlobal(QCursor::pos());
1222
 
        if(cp.x() >= 0 && cp.x() < canvas->width() && sp.y() >= 0 && sp.y() < editor->height())
1223
 
          offset = cp.x();
1224
 
        horizontalZoom(false, offset);  
 
1244
        horizontalZoom(false, QCursor::pos());
1225
1245
        return;
1226
1246
        }
1227
1247
 
1228
1248
  QWidget::keyPressEvent(event);
1229
1249
}
1230
1250
 
1231
 
void Arranger::horizontalZoom(bool zoom_in, int pos_offset)
 
1251
void Arranger::horizontalZoom(bool zoom_in, const QPoint& glob_pos)
1232
1252
{
1233
1253
  int mag = hscroll->mag();
1234
1254
  int zoomlvl = ScrollScale::getQuickZoomLevel(mag);
1243
1263
        zoomlvl--;
1244
1264
  }
1245
1265
  int newmag = ScrollScale::convertQuickZoomLevelToMag(zoomlvl);
1246
 
  hscroll->setMag(newmag, pos_offset);
 
1266
 
 
1267
  QPoint cp = canvas->mapFromGlobal(glob_pos);
 
1268
  QPoint sp = editor->mapFromGlobal(glob_pos);
 
1269
  if(cp.x() >= 0 && cp.x() < canvas->width() && sp.y() >= 0 && sp.y() < editor->height())
 
1270
    hscroll->setMag(newmag, cp.x());
 
1271
}
 
1272
 
 
1273
void Arranger::horizontalZoom(int mag, const QPoint& glob_pos)
 
1274
{
 
1275
  QPoint cp = canvas->mapFromGlobal(glob_pos);
 
1276
  QPoint sp = editor->mapFromGlobal(glob_pos);
 
1277
  if(cp.x() >= 0 && cp.x() < canvas->width() && sp.y() >= 0 && sp.y() < editor->height())
 
1278
    hscroll->setMag(hscroll->mag() + mag, cp.x());
1247
1279
}
1248
1280
 
1249
1281
} // namespace MusEGui