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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Rosegarden
A MIDI and audio sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <[email protected]>,
Chris Cannam <[email protected]>,
Richard Bown <[email protected]>
The moral rights of Guillaume Laurent, Chris Cannam, and Richard
Bown to claim authorship of this work have been asserted.
Other copyrights also apply to some parts of this work. Please
see the AUTHORS file and individual file headers for details.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include "DiatonicPitchChooser.h"
#include <iostream>
#include <tdelocale.h>
#include "base/NotationRules.h"
#include "base/NotationTypes.h"
#include "gui/general/MidiPitchLabel.h"
#include "PitchDragLabel.h"
#include <kcombobox.h>
#include <tqgroupbox.h>
#include <tqhbox.h>
#include <tqlabel.h>
#include <tqspinbox.h>
#include <tqstring.h>
#include <tqwidget.h>
namespace Rosegarden
{
DiatonicPitchChooser::DiatonicPitchChooser(TQString title,
TQWidget *parent,
int defaultNote,
int defaultPitch,
int defaultOctave) :
TQGroupBox(1, Qt::Horizontal, title, parent),
m_defaultPitch(defaultPitch)
{
m_pitchDragLabel = new PitchDragLabel(this, defaultPitch);
TQHBox *hbox = new TQHBox(this);
hbox->setSpacing(6);
m_step = new KComboBox( hbox );
m_step->setSizeLimit( 7 );
m_step->insertItem(i18n("C"));
m_step->insertItem(i18n("D"));
m_step->insertItem(i18n("E"));
m_step->insertItem(i18n("F"));
m_step->insertItem(i18n("G"));
m_step->insertItem(i18n("A"));
m_step->insertItem(i18n("B"));
m_step->setCurrentItem(defaultNote);
m_octave = new KComboBox( hbox );
m_octave->insertItem(i18n("-2"));
m_octave->insertItem(i18n("-1"));
m_octave->insertItem(i18n("0"));
m_octave->insertItem(i18n("1"));
m_octave->insertItem(i18n("2"));
m_octave->insertItem(i18n("3"));
m_octave->insertItem(i18n("4"));
m_octave->insertItem(i18n("5"));
m_octave->insertItem(i18n("6"));
m_octave->insertItem(i18n("7"));
m_octave->setCurrentItem(defaultOctave);
m_accidental = new KComboBox( hbox );
m_accidental->insertItem(i18n("double flat"));
m_accidental->insertItem(i18n("flat"));
m_accidental->insertItem(i18n("natural"));
m_accidental->insertItem(i18n("sharp"));
m_accidental->insertItem(i18n("double sharp"));
m_accidental->setCurrentItem(2); // default: natural
m_pitchLabel = new TQLabel(TQString("%1").arg(getPitch()), hbox);
m_pitchLabel->setMinimumWidth(40);
connect(m_accidental, TQT_SIGNAL(activated(int)),
this, TQT_SLOT(slotSetAccidental(int)));
connect(m_octave, TQT_SIGNAL(activated(int)),
this, TQT_SLOT(slotSetOctave(int)));
connect(m_step, TQT_SIGNAL(activated(int)),
this, TQT_SLOT(slotSetStep(int)));
//connect(m_pitch, TQT_SIGNAL(valueChanged(int)),
// this, TQT_SIGNAL(pitchChanged(int)));
//connect(m_pitch, TQT_SIGNAL(valueChanged(int)),
// this, TQT_SIGNAL(preview(int)));
connect(m_pitchDragLabel, TQT_SIGNAL(pitchDragged(int,int,int)),
this, TQT_SLOT(slotSetNote(int,int,int)));
//connect(m_pitchDragLabel, TQT_SIGNAL(pitchChanged(int)),
// this, TQT_SLOT(slotSetPitch(int)));
connect(m_pitchDragLabel, TQT_SIGNAL(pitchChanged(int,int,int)),
this, TQT_SLOT(slotSetNote(int,int,int)));
//connect(m_pitchDragLabel, TQT_SIGNAL(pitchChanged(int)),
// this, TQT_SIGNAL(pitchChanged(int)));
connect(m_pitchDragLabel, TQT_SIGNAL(pitchDragged(int,int,int)),
this, TQT_SIGNAL(noteChanged(int,int,int)));
connect(m_pitchDragLabel, TQT_SIGNAL(pitchChanged(int,int,int)),
this, TQT_SIGNAL(noteChanged(int,int,int)));
connect(m_pitchDragLabel, TQT_SIGNAL(preview(int)),
this, TQT_SIGNAL(preview(int)));
}
int
DiatonicPitchChooser::getPitch() const
{
return 12 * m_octave->currentItem() + scale_Cmajor[m_step->currentItem()] +
(m_accidental->currentItem() - 2);
}
int
DiatonicPitchChooser::getAccidental()
{
return m_accidental->currentItem() - 2;
}
void
DiatonicPitchChooser::slotSetPitch(int pitch)
{
if (m_pitchDragLabel->getPitch() != pitch)
m_pitchDragLabel->slotSetPitch(pitch);
m_octave->setCurrentItem((int)(((long) pitch) / 12));
int step = steps_Cmajor[pitch % 12];
m_step->setCurrentItem(step);
int pitchChange = (pitch % 12) - scale_Cmajor[step];
m_accidental->setCurrentItem(pitchChange + 2);
m_pitchLabel->setText(TQString("%1").arg(pitch));
update();
}
void
DiatonicPitchChooser::slotSetStep(int step)
{
if (m_step->currentItem() != step)
m_step->setCurrentItem(step);
std::cout << "slot_step called" << std::endl;
setLabelsIfNeeded();
update();
}
void
DiatonicPitchChooser::slotSetOctave(int octave)
{
if (m_octave->currentItem() != octave)
m_octave->setCurrentItem(octave);
setLabelsIfNeeded();
update();
}
/** input 0..4: doubleflat .. doublesharp */
void
DiatonicPitchChooser::slotSetAccidental(int accidental)
{
if (m_accidental->currentItem() != accidental)
m_accidental->setCurrentItem(accidental);
setLabelsIfNeeded();
update();
}
/** sets the m_pitchDragLabel and m_pitchLabel if needed */
void
DiatonicPitchChooser::setLabelsIfNeeded()
{
//if (m_pitchDragLabel->)
//{
m_pitchDragLabel->slotSetPitch(getPitch(), m_octave->currentItem(), m_step->currentItem());
//}
m_pitchLabel->setText(TQString("%1").arg(getPitch()));
}
void
DiatonicPitchChooser::slotSetNote(int pitch, int octave, int step)
{
//if (m_pitch->value() != p)
// m_pitch->setValue(p);
if (m_pitchDragLabel->getPitch() != pitch)
m_pitchDragLabel->slotSetPitch(pitch, octave, step);
m_octave->setCurrentItem(octave);
m_step->setCurrentItem(step);
int pitchOffset = pitch - (octave * 12 + scale_Cmajor[step]);
m_accidental->setCurrentItem(pitchOffset + 2);
//MidiPitchLabel pl(p);
m_pitchLabel->setText(TQString("%1").arg(pitch));
update();
}
void
DiatonicPitchChooser::slotResetToDefault()
{
slotSetPitch(m_defaultPitch);
}
int
DiatonicPitchChooser::getOctave() const
{
return m_octave->currentItem();
}
int
DiatonicPitchChooser::getStep() const
{
return m_step->currentItem();
}
}
#include "DiatonicPitchChooser.moc"
|