File: quant.cpp

package info (click to toggle)
muse 0.6.3-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,936 kB
  • ctags: 7,446
  • sloc: cpp: 66,262; sh: 8,355; makefile: 755; ansic: 172
file content (149 lines) | stat: -rw-r--r-- 4,248 bytes parent folder | download
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
//=========================================================
//  MusE
//  Linux Music Editor
//    $Id: quant.cpp,v 1.1.1.1 2003/10/29 10:05:24 wschweer Exp $
//  (C) Copyright 1999,2000 Werner Schweer (ws@seh.de)
//=========================================================

#include <stdio.h>
#include <qgroupbox.h>
#include <qscrollbar.h>
#include <qlayout.h>
#include "symbols.h"
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qlistbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qvbox.h>
#include <qhbox.h>
#include <qradiobutton.h>
#include <qpushbutton.h>
#include <qbuttongroup.h>
#include <qtabwidget.h>
#include "score.h"
#include "quant.h"
#include "ncanvas.h"
#include "posedit.h"

//---------------------------------------------------------
//   showQuantDialog
//---------------------------------------------------------

bool ScoreCanvas::showQuantDialog(int* tick, int* nq, int* rq)
      {
      if (!quantConfig) {
            quantConfig = new QuantDialog(this, "quantConfig");
            }
      quantConfig->setTick(*tick);
      quantConfig->setNoteQuant(*nq);
      quantConfig->setRestQuant(*rq);
      if (quantConfig->exec()) {
            *nq = quantConfig->noteQuant();
            *rq = quantConfig->restQuant();
            *tick = quantConfig->tick();
            return true;
            }
      return false;
      }

//---------------------------------------------------------
//   quant2tick
//    >> from sconfig.c <<
//---------------------------------------------------------

static int quant2tick(int q)
      {
      int tab[] = {
            16, 32,  64, 128, 256,
            24, 48,  96, 192, 384
            };
      return tab[q];
      }
static int tick2quant(int tick)
      {
      switch(tick) {
            case 16:    return 0;
            case 32:    return 1;
            case 64:    return 2;
            case 128:   return 3;
            case 256:   return 4;
            case 24:    return 5;
            case 48:    return 6;
            case 96:    return 7;
            case 192:   return 8;
            case 384:   return 9;
            default:
                  printf("illeagal quant value\n");
                  break;
            }
      return 0;
      }


extern QComboBox* createQuantCombo(QWidget* parent);

//---------------------------------------------------------
//   QuantDialog
//---------------------------------------------------------

QuantDialog::QuantDialog(QWidget* parent, const char* name)
   : QDialog(parent, name, true)
      {
      setCaption(tr("Display Quantize"));
      QGridLayout* grid = new QGridLayout(this, 1, 1, 0, -1, "grid");

      QWidget* w3 = new QGroupBox(2, Horizontal, QString::null, this, "w3");
      tl = new PosEdit(w3);
      new QLabel(tr("Position"), w3);
      quant1 = createQuantCombo(w3);
      new QLabel(tr("Note Quantize"), w3);
      quant2 = createQuantCombo(w3);
      new QLabel(tr("Rest Quantize"), w3);

      //---------------------------------------------------
      //    Cancel & Apply & OK Buttons
      //---------------------------------------------------

      QHBoxLayout* l4 = new QHBoxLayout(0, "l4");  // TODO: destroy
      QPushButton* b1 = new QPushButton(tr("Ok"), this, "b1");
      b1->setDefault(true);
      QPushButton* b3 = new QPushButton(tr("Cancel"), this, "b3");
      b1->setFixedWidth(80);
      b3->setFixedWidth(80);
      l4->addWidget(b1);
      l4->addSpacing(12);
      l4->addWidget(b3);
      l4->addStretch(1);
      connect(b1, SIGNAL(clicked()), SLOT(accept()));
      connect(b3, SIGNAL(clicked()), SLOT(reject()));

      grid->addWidget(w3, 0, 0);
      grid->addLayout(l4, 1, 0);
      }

int QuantDialog::noteQuant() const
      {
      return quant2tick(quant1->currentItem());
      }
int QuantDialog::restQuant() const
      {
      return quant2tick(quant2->currentItem());
      }
int QuantDialog::tick() const
      {
      return tl->pos().posTick();
      }
void QuantDialog::setTick(int v)
      {
      return tl->setValue(v);
      }
void QuantDialog::setNoteQuant(int val)
      {
      quant1->setCurrentItem(tick2quant(val));
      }
void QuantDialog::setRestQuant(int val)
      {
      quant2->setCurrentItem(tick2quant(val));
      }