summaryrefslogtreecommitdiff
path: root/noncore/multimedia/powerchord/powerchordbase.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/powerchord/powerchordbase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/powerchord/powerchordbase.cpp592
1 files changed, 592 insertions, 0 deletions
diff --git a/noncore/multimedia/powerchord/powerchordbase.cpp b/noncore/multimedia/powerchord/powerchordbase.cpp
new file mode 100644
index 0000000..0b97984
--- a/dev/null
+++ b/noncore/multimedia/powerchord/powerchordbase.cpp
@@ -0,0 +1,592 @@
1/****************************************************************************
2** Form implementation generated from reading ui file 'powerchordbase.ui'
3**
4** Created: Sun Jan 13 23:05:11 2002
5** by: The User Interface Compiler (uic)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9#include "powerchordbase.h"
10
11#include "fretboard.h"
12#include "vumeter.h"
13#include "gs.h"
14#include <qcombobox.h>
15#include <qframe.h>
16#include <qlabel.h>
17#include <qlistbox.h>
18#include <qpushbutton.h>
19#include <qspinbox.h>
20#include <qtabwidget.h>
21#include <qlayout.h>
22#include <qvariant.h>
23#include <qtooltip.h>
24#include <qwhatsthis.h>
25#include <qimage.h>
26#include <qpixmap.h>
27#include <qbitmap.h>
28#include <qpe/resource.h>
29
30
31/*
32 * Constructs a PowerchordBase which is a child of 'parent', with the
33 * name 'name' and widget flags set to 'f'
34 */
35PowerchordBase::PowerchordBase( QWidget* parent, const char* name, WFlags fl )
36 : QWidget( parent, name, fl )
37{
38 simulation_timer = 0;
39 audio_timer = 0;
40
41 // setPalette( QPalette( QColor( 232, 227, 215) ) );
42
43 // QPixmap image0(QString("/opt/Qtopia/pics/powerchord/image0"));
44 QPixmap image1 = Resource::loadPixmap( "powerchord/image1");
45 QPixmap image2 = Resource::loadPixmap( "powerchord/image2");
46 QPixmap image3 = Resource::loadPixmap( "powerchord/image3");
47 QPixmap image4 = Resource::loadPixmap( "powerchord/image4");
48 QPixmap image5 = Resource::loadPixmap( "powerchord/image5");
49 image6 = Resource::loadPixmap( "powerchord/image6");
50 image_open = Resource::loadPixmap( "powerchord/image_open");
51
52 // image0.setMask(image0.createHeuristicMask());
53 image1.setMask(image1.createHeuristicMask());
54 // image2.setMask(image2.createHeuristicMask());
55 // image3.setMask(image3.createHeuristicMask());
56 // image4.setMask(image4.createHeuristicMask());
57 // image5.setMask(image5.createHeuristicMask());
58 // image6->setMask(image6->createHeuristicMask());
59 // image_open->setMask(image_open->createHeuristicMask());
60
61 if ( !name )
62 setName( "PowerchordBase" );
63 resize( 240, 284 );
64 setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, sizePolicy().hasHeightForWidth() ) );
65 setMinimumSize( QSize( 240, 284 ) );
66 setMaximumSize( QSize( 240, 284 ) );
67 setCaption( tr( "Powerchord" ) );
68
69 tabs = new QTabWidget( this, "tabs" );
70 tabs->setEnabled( TRUE );
71 tabs->setGeometry( QRect( 0, 0, 240, 286 ) );
72 tabs->setTabPosition( QTabWidget::Bottom );
73
74 tab = new QWidget( tabs, "tab" );
75
76 chordkey = new QComboBox( FALSE, tab, "chordkey" );
77 chordkey->insertItem( tr( "maj" ) );
78 chordkey->insertItem( tr( "min" ) );
79 chordkey->insertItem( tr( "7th" ) );
80 chordkey->insertItem( tr( "m7" ) );
81 chordkey->insertItem( tr( "maj7" ) );
82 chordkey->insertItem( tr( "6th" ) );
83 chordkey->insertItem( tr( "m6th" ) );
84 chordkey->insertItem( tr( "aug" ) );
85 chordkey->insertItem( tr( "dim" ) );
86 chordkey->insertItem( tr( "sus4" ) );
87 chordkey->insertItem( tr( "7sus4" ) );
88 chordkey->insertItem( tr( "9th" ) );
89 chordkey->insertItem( tr( "add9" ) );
90 chordkey->insertItem( tr( "m9th" ) );
91 chordkey->insertItem( tr( "maj9" ) );
92 chordkey->insertItem( tr( "sus2" ) );
93 chordkey->insertItem( tr( "7sus2" ) );
94 chordkey->insertItem( tr( "11th" ) );
95 chordkey->insertItem( tr( "m11th" ) );
96 chordkey->insertItem( tr( "13th" ) );
97 chordkey->insertItem( tr( "m13th" ) );
98 chordkey->insertItem( tr( "maj13" ) );
99 chordkey->insertItem( tr( "6/9" ) );
100 chordkey->insertItem( tr( "flat5" ) );
101 chordkey->insertItem( tr( "7#9" ) );
102 chordkey->insertItem( tr( QString::fromUtf8( "ø7" ) ) );
103 chordkey->insertItem( tr( "5" ) );
104 chordkey->setGeometry( QRect( 40, 0, 51, 21 ) );
105
106 chordfret = new QComboBox( FALSE, tab, "chordfret" );
107 chordfret->insertItem( tr( "open" ) );
108 chordfret->insertItem( tr( "1st" ) );
109 chordfret->insertItem( tr( "2nd" ) );
110 chordfret->insertItem( tr( "3rd" ) );
111 chordfret->insertItem( tr( "4th" ) );
112 chordfret->insertItem( tr( "5th" ) );
113 chordfret->insertItem( tr( "6th" ) );
114 chordfret->insertItem( tr( "7th" ) );
115 chordfret->insertItem( tr( "8th" ) );
116 chordfret->insertItem( tr( "9th" ) );
117 chordfret->insertItem( tr( "10th" ) );
118 chordfret->insertItem( tr( "11th" ) );
119 chordfret->insertItem( tr( "12th" ) );
120 chordfret->insertItem( tr( "13th" ) );
121 chordfret->insertItem( tr( "14th" ) );
122 chordfret->insertItem( tr( "15th" ) );
123 chordfret->insertItem( tr( "16th" ) );
124 chordfret->setGeometry( QRect( 90, 0, 55, 21 ) ); //cxm less 5 width
125
126 chordnote = new QComboBox( FALSE, tab, "chordnote" );
127 chordnote->insertItem( tr( "C" ) );
128 chordnote->insertItem( tr( "C#" ) );
129 chordnote->insertItem( tr( "D" ) );
130 chordnote->insertItem( tr( "Eb" ) );
131 chordnote->insertItem( tr( "E" ) );
132 chordnote->insertItem( tr( "F" ) );
133 chordnote->insertItem( tr( "F#" ) );
134 chordnote->insertItem( tr( "G" ) );
135 chordnote->insertItem( tr( "G#" ) );
136 chordnote->insertItem( tr( "A" ) );
137 chordnote->insertItem( tr( "Bb" ) );
138 chordnote->insertItem( tr( "B" ) );
139 chordnote->setGeometry( QRect( 0, 0, 40, 21 ) );
140 chordnote->setCurrentItem( 9 );
141
142 QWidget* privateLayoutWidget = new QWidget( tab, "Layout1" );
143 privateLayoutWidget->setGeometry( QRect( 5, 232, 160, 20 ) );
144 Layout1 = new QHBoxLayout( privateLayoutWidget );
145 Layout1->setSpacing( 6 );
146 Layout1->setMargin( 0 );
147
148 s1_1 = new QLabel( privateLayoutWidget, "s1_1" );
149 s1_1->setText( tr( "E" ) );
150 s1_1->setAlignment( int( QLabel::AlignCenter ) );
151 Layout1->addWidget( s1_1 );
152
153 s1_2 = new QLabel( privateLayoutWidget, "s1_2" );
154 s1_2->setText( tr( "A" ) );
155 s1_2->setAlignment( int( QLabel::AlignCenter ) );
156 Layout1->addWidget( s1_2 );
157
158 s1_3 = new QLabel( privateLayoutWidget, "s1_3" );
159 s1_3->setText( tr( "E" ) );
160 s1_3->setAlignment( int( QLabel::AlignCenter ) );
161 Layout1->addWidget( s1_3 );
162
163 s1_4 = new QLabel( privateLayoutWidget, "s1_4" );
164 s1_4->setText( tr( "A" ) );
165 s1_4->setAlignment( int( QLabel::AlignCenter ) );
166 Layout1->addWidget( s1_4 );
167
168 s1_5 = new QLabel( privateLayoutWidget, "s1_5" );
169 s1_5->setText( tr( "C#" ) );
170 s1_5->setAlignment( int( QLabel::AlignCenter ) );
171 Layout1->addWidget( s1_5 );
172
173 s1_6 = new QLabel( privateLayoutWidget, "s1_6" );
174 s1_6->setText( tr( "E" ) );
175 s1_6->setAlignment( int( QLabel::AlignCenter ) );
176 Layout1->addWidget( s1_6 );
177
178 // sound_label = new QLabel( tab, "sound_label" );
179 // sound_label->setGeometry( QRect( 185, 160, 32, 17 ) );
180 // sound_label->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sound_label->sizePolicy().hasHeightForWidth() ) );
181 // sound_label->setPixmap( image0 );
182 // sound_label->pixmap()->setMask(*image0.mask());
183 // sound_label->setScaledContents( TRUE );
184 // sound_label->setBackgroundMode( QWidget::PaletteButton );
185 // sound_label->setBackgroundColor(this->backgroundColor());
186 // sound_label->setPalette( QPalette( QColor( 232, 227, 215) ) );
187
188
189 Frame6 = new QFrame( tab, "Frame6" );
190 Frame6->setGeometry( QRect( 170, 145, 66, 10 ) );
191 Frame6->setFrameShape( QFrame::HLine );
192 Frame6->setFrameShadow( QFrame::Raised );
193
194 chordshow_label = new QLabel( tab, "chordshow_label" );
195 chordshow_label->setGeometry( QRect( 185, 60, 32, 17 ) );
196 // chordshow_label->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, chordshow_label->sizePolicy().hasHeightForWidth() ) );
197 chordshow_label->setFrameShape( QLabel::NoFrame );
198 chordshow_label->setPixmap( image1 );
199 chordshow_label->setScaledContents( TRUE );
200 // chordshow_label->setBackgroundMode( QWidget::PaletteButton );
201
202 transport_rec = new QPushButton( tab, "transport_rec" );
203 transport_rec->setGeometry( QRect( 170, 80, 30, 30 ) );
204 transport_rec->setText( tr( "" ) );
205 transport_rec->setPixmap( image2 );
206
207 play_sound = new QPushButton( tab, "play_sound" );
208 play_sound->setGeometry( QRect( 170, 180, 60, 55 ) );
209 play_sound->setText( tr( "" ) );
210 play_sound->setPixmap( image3 );
211
212 Frame6_2 = new QFrame( tab, "Frame6_2" );
213 Frame6_2->setGeometry( QRect( 170, 45, 66, 10 ) );
214 Frame6_2->setFrameShape( QFrame::HLine );
215 Frame6_2->setFrameShadow( QFrame::Raised );
216
217 transport_play = new QPushButton( tab, "transport_play" );
218 transport_play->setEnabled( FALSE );
219 transport_play->setGeometry( QRect( 200, 80, 30, 30 ) );
220 transport_play->setText( tr( "" ) );
221 transport_play->setPixmap( image3 );
222
223 transport_rew = new QPushButton( tab, "transport_rew" );
224 transport_rew->setEnabled( FALSE );
225 transport_rew->setGeometry( QRect( 170, 110, 30, 30 ) );
226 transport_rew->setText( tr( "" ) );
227 transport_rew->setPixmap( image4 );
228
229 transport_fwd = new QPushButton( tab, "transport_fwd" );
230 transport_fwd->setEnabled( FALSE );
231 transport_fwd->setGeometry( QRect( 200, 110, 30, 30 ) );
232 transport_fwd->setText( tr( "" ) );
233 transport_fwd->setPixmap( image5 );
234
235 chordname = new QLabel( tab, "chordname" );
236 chordname->setGeometry( QRect( 146, 0, 90, 20 ) ); //cxm moved l 5
237 chordname->setText( tr( "A" ) );
238 chordname->setAlignment( int( QLabel::AlignCenter ) );
239 QToolTip::add( chordname, tr( "" ) );
240
241 synth = new gs();
242 tuner = new gt();
243 frets = new FretBoard( tab, "frets" );
244 frets->setGeometry( QRect( 0, 20, 168, 210 ) );
245 tabs->insertTab( tab, tr( "Guitar" ) );
246
247 tab_2 = new QWidget( tabs, "tab_2" );
248
249 optlab2 = new QLabel( tab_2, "optlab2" );
250 optlab2->setGeometry( QRect( 9, 58, 120, 41 ) );
251 optlab2->setText( tr( "Alternative tunings are possible" ) );
252 optlab2->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter | QLabel::AlignLeft ) );
253
254 span = new QComboBox( FALSE, tab_2, "span" );
255 span->insertItem( tr( "2" ) );
256 span->insertItem( tr( "3" ) );
257 span->insertItem( tr( "4" ) );
258 span->insertItem( tr( "5" ) );
259 span->insertItem( tr( "6" ) );
260 span->setGeometry( QRect( 180, 20, 50, 21 ) );
261 span->setCurrentItem( 1 );
262
263 TextLabel1 = new QLabel( tab_2, "TextLabel1" );
264 TextLabel1->setGeometry( QRect( 3, 109, 226, 140 ) );
265 TextLabel1->setText( tr( QString::fromUtf8( "©2002 Camilo Mesias\n"
266"camilo@mesias.co.uk\n"
267"Version 0.0.7 beta" ) ) );
268 TextLabel1->setAlignment( int( QLabel::AlignBottom | QLabel::AlignLeft ) );
269
270 tuning = new QComboBox( FALSE, tab_2, "tuning" );
271 tuning->insertItem( tr( "EADGBE" ) );
272 tuning->insertItem( tr( "EBEG#BE" ) );
273 tuning->insertItem( tr( "EAEAC#E" ) );
274 tuning->insertItem( tr( "EADF#BE" ) );
275 tuning->insertItem( tr( "EADGCF" ) );
276 tuning->insertItem( tr( "DADGAD" ) );
277 tuning->insertItem( tr( "DGCGCD" ) );
278 tuning->insertItem( tr( "DADF#AD" ) );
279 tuning->insertItem( tr( "DADGBE" ) );
280 tuning->insertItem( tr( "DGDGBD" ) );
281 tuning->insertItem( tr( "DADACD" ) );
282 tuning->insertItem( tr( "CGCGAE" ) );
283 tuning->insertItem( tr( "FADGBE" ) );
284 tuning->insertItem( tr( "G minor" ) );
285 tuning->setGeometry( QRect( 140, 70, 91, 21 ) );
286
287 optlab1 = new QLabel( tab_2, "optlab1" );
288 optlab1->setGeometry( QRect( 8, 8, 160, 40 ) );
289 optlab1->setText( tr( "Span: the greatest number of frets over which you want chords to be generated" ) );
290 optlab1->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter | QLabel::AlignLeft ) );
291 tabs->insertTab( tab_2, tr( "Options" ) );
292
293 Tuner = new QWidget( tabs, "Tuner" );
294
295 Frame4 = new QFrame( Tuner, "Frame4" );
296 Frame4->setGeometry( QRect( 0, 0, 230, 126 ) );
297 Frame4->setFrameShape( QFrame::Box );
298 Frame4->setFrameShadow( QFrame::Raised );
299
300 vu = new VUMeter( Frame4, "vu" );
301 vu->setGeometry( QRect( 5, 5, 220, 115 ) );
302
303 tuner_note = new QComboBox( FALSE, Tuner, "tuner_note" );
304 tuner_note->insertItem( tr( "auto" ) );
305 tuner_note->insertItem( tr( "E" ) );
306 tuner_note->insertItem( tr( "D" ) );
307 tuner_note->insertItem( tr( "G" ) );
308 tuner_note->insertItem( tr( "A" ) );
309 tuner_note->insertItem( tr( "B" ) );
310 tuner_note->insertItem( tr( "C" ) );
311 tuner_note->insertItem( tr( "F" ) );
312 tuner_note->setGeometry( QRect( 5, 160, 90, 20 ) );
313
314 Frame8 = new QFrame( Tuner, "Frame8" );
315 Frame8->setGeometry( QRect( -2, 188, 231, 10 ) );
316 Frame8->setFrameShape( QFrame::HLine );
317 Frame8->setFrameShadow( QFrame::Raised );
318
319 tuner_start = new QPushButton( Tuner, "tuner_start" );
320 tuner_start->setGeometry( QRect( 100, 155, 91, 30 ) );
321 tuner_start->setText( tr( "Start" ) );
322
323 tuner_lab1 = new QLabel( Tuner, "tuner_lab1" );
324 tuner_lab1->setGeometry( QRect( 10, 130, 100, 21 ) );
325 tuner_lab1->setText( tr( "Tuner operation" ) );
326
327 tuner_lab2 = new QLabel( Tuner, "tuner_lab2" );
328 tuner_lab2->setGeometry( QRect( 10, 200, 100, 16 ) );
329 tuner_lab2->setText( tr( "Pitch calibration" ) );
330
331 tuner_calib_note = new QComboBox( FALSE, Tuner, "tuner_calib_note" );
332 tuner_calib_note->insertItem( tr( "A" ) );
333 tuner_calib_note->insertItem( tr( "C" ) );
334 tuner_calib_note->setGeometry( QRect( 5, 225, 90, 21 ) );
335
336 tuner_calib_freq = new QSpinBox( Tuner, "tuner_calib_freq" );
337 tuner_calib_freq->setGeometry( QRect( 105, 225, 71, 21 ) );
338 tuner_calib_freq->setSuffix( tr( "Hz" ) );
339 tuner_calib_freq->setWrapping( TRUE );
340 tuner_calib_freq->setMaxValue( 500 );
341 tuner_calib_freq->setMinValue( 300 );
342 tuner_calib_freq->setValue( 440 );
343
344 tuner_lab3 = new QLabel( Tuner, "tuner_lab3" );
345 tuner_lab3->setGeometry( QRect( 185, 225, 40, 21 ) );
346 tuner_lab3->setText( tr( "Pitch" ) );
347
348 tuner_pic1 = new QLabel( Tuner, "tuner_pic1" );
349 tuner_pic1->setGeometry( QRect( 195, 155, 31, 31 ) );
350 tuner_pic1->setFrameShape( QLabel::NoFrame );
351 tuner_pic1->setPixmap( image6 );
352 tuner_pic1->setScaledContents( TRUE );
353 tabs->insertTab( Tuner, tr( "Tuner" ) );
354
355 tab_3 = new QWidget( tabs, "tab_3" );
356
357 chordlistlab1 = new QLabel( tab_3, "chordlistlab1" );
358 chordlistlab1->setGeometry( QRect( 5, 5, 216, 16 ) );
359 chordlistlab1->setText( tr( "Chord list" ) );
360
361 chordlist = new QListBox( tab_3, "chordlist" );
362 chordlist->setGeometry( QRect( 5, 25, 220, 200 ) );
363
364 list_remove_btn = new QPushButton( tab_3, "list_remove_btn" );
365 list_remove_btn->setGeometry( QRect( 150, 230, 71, 25 ) );
366 list_remove_btn->setText( tr( "Remove" ) );
367 tabs->insertTab( tab_3, tr( "Chords" ) );
368
369 // hope this does what it's supposed to!!
370 // setPalette( QPalette( QColor( 232, 227, 215) ) );
371
372 // signals and slots connections
373
374 //cxm
375 connect( tuning, SIGNAL( activated(int) ), frets, SLOT( Tune(int) ) );
376 connect( span, SIGNAL( activated(int) ), frets, SLOT( Span(int) ) );
377 connect( transport_rec, SIGNAL( clicked() ), this, SLOT( transport_rec_cb() ));
378 connect( play_sound, SIGNAL( clicked() ), this, SLOT( play_chord_cb() ));
379 connect( tuner_start, SIGNAL( clicked() ), this, SLOT( tuner_start_cb() ));
380 connect( tuner_note, SIGNAL( textChanged(const QString&) ), vu, SLOT( AnnotL(const QString&) ));
381 connect( this, SIGNAL( frequency_change(int) ), vu, SLOT( Value(int) ));
382
383 connect( chordnote, SIGNAL( activated(int) ), frets, SLOT( Base(int) ) );
384 connect( chordkey, SIGNAL( activated(int) ), frets, SLOT( Chord(int) ) );
385 connect( chordfret, SIGNAL( activated(int) ), frets, SLOT( Fret(int) ) );
386 connect( list_remove_btn, SIGNAL( clicked() ), this, SLOT( list_remove_cb() ) );
387 connect( frets, SIGNAL( s1nameChanged(const QString &) ), s1_1, SLOT( setText(const QString&) ) );
388 connect( frets, SIGNAL( s2nameChanged(const QString &) ), s1_2, SLOT( setText(const QString&) ) );
389 connect( frets, SIGNAL( s3nameChanged(const QString &) ), s1_3, SLOT( setText(const QString&) ) );
390 connect( frets, SIGNAL( s4nameChanged(const QString &) ), s1_4, SLOT( setText(const QString&) ) );
391 connect( frets, SIGNAL( s5nameChanged(const QString &) ), s1_5, SLOT( setText(const QString&) ) );
392 connect( frets, SIGNAL( s6nameChanged(const QString &) ), s1_6, SLOT( setText(const QString&) ) );
393 connect( frets, SIGNAL( nameChanged(const QString &) ), chordname, SLOT( setText(const QString&) ) );
394}
395
396
397static int known=0;
398#include <qmessagebox.h>
399void PowerchordBase::transport_rec_cb(){
400 chordlist->insertItem(chordname->text(),-1);
401 if (!known){
402 QMessageBox::information(this, "Powerchord", "This chord has been saved\ninto the list of chords,\nfor later playback.");
403 known = 1;
404 }
405}
406void PowerchordBase::list_remove_cb(){
407 if (chordlist->count() > 0){
408 chordlist->removeItem(0);
409 }
410}
411void PowerchordBase::play_chord_cb(){
412 // QMessageBox::information(this, "Coming soon!", "This button plays\nthe chord by synthesizing\nthe sound of the notes.");
413
414
415 if (audio_timer){
416 audio_timer->stop();
417 // set pixmap?
418 synth->Stop();
419 delete(audio_timer);
420 audio_timer = 0;
421 }else{
422 // get notes from chord engine
423
424 int note;
425 int base;
426 int octave;
427 note = frets->ce.noteindex(0);
428 if (note >= 0){
429 //fprintf(stderr, "Note was %d\n", note);
430 base = note % 12;
431 octave = note / 12;
432 synth->note_start(0, base, octave);
433 }else{
434 // subtle bug here - replay second note if 1st one muted
435 note = frets->ce.noteindex(1);
436 base = note % 12;
437 octave = note / 12;
438 synth->note_start(1, base, octave);
439
440 }
441
442 // init synth
443 if (synth->Play()){
444 // error
445 QMessageBox::information(this, "Powerchord", "Unable to open device for sound playback - check that no other application is using it.");
446 return;
447 }
448 synth->fill_buffer();
449
450 // start timer
451 audio_timer = new QTimer();
452 connect(audio_timer, SIGNAL( timeout() ), this, SLOT( audio_cb() ));
453 // set pixmap on player?
454 audio_timer->start(19); // 19 msec (fudge factor!!)
455 }
456}
457
458
459
460void PowerchordBase::audio_cb(){
461 // play the next bit of audio until quiet
462
463 // strum timing
464#define INTERVAL 2
465
466 if ((synth->Frames() % INTERVAL) == 0){
467 int string = synth->Frames() / INTERVAL;
468 if (string <= 5){
469 int note;
470 int base;
471 int octave;
472 note = frets->ce.noteindex(string);
473 // check not muted...
474 if (note > 0){
475 base = note % 12;
476 octave = note / 12;
477 synth->note_start(string, base, octave);
478 }
479 }
480 }
481
482 if (synth->Playing()){
483 synth->write_buffer();
484 synth->fill_buffer();
485 }else{
486 audio_timer->stop();
487 // set pixmap?
488 synth->Stop();
489 delete(audio_timer);
490 audio_timer = 0;
491 }
492}
493
494// the real tuner
495// void PowerchordBase::tuner_start_cb(){
496
497// if (tuner->Listening()){
498// simulation_timer->stop();
499// tuner->Stop();
500// tuner_pic1->setPixmap( *image6 );
501
502// }else{
503// tuner_pic1->setPixmap( *image_open );
504
505// if (!simulation_timer){
506// simulation_timer = new QTimer();
507
508
509// connect(simulation_timer, SIGNAL( timeout() ), this, SLOT( tuner_cb() ));
510// }
511
512// simulation_timer->start(50);
513// tuner->Listen();
514
515// }
516// }
517
518void PowerchordBase::tuner_cb(){
519 if (tuner->Listening()){
520 tuner->read_buffer();
521 tuner->process_buffer();
522
523 // update gui
524 // do something with the note: tuner->Note()
525 emit frequency_change(tuner->Tuning());
526
527 }else{
528 simulation_timer->stop();
529 tuner->Stop();
530 tuner_pic1->setPixmap( image6 );
531 }
532}
533
534
535void PowerchordBase::tuner_start_cb(){
536 if (0 == QMessageBox::information(this, "Powerchord", "Using the microphone,\nthe note's frequency\nis analysed. This\nis a simulation.", "OK", "Cancel", 0, 1)){
537 if (simulation_timer){
538 simulation_timer->stop();
539 }else{
540 simulation_timer = new QTimer();
541 connect(simulation_timer, SIGNAL( timeout() ), this, SLOT( tuner_simulation_cb() ));
542
543 }
544 simulation_x = -45;
545 simulation_v = 0;
546 simulation_iter = 0;
547
548 tuner_pic1->setPixmap( image_open );
549 simulation_timer->start(100);
550 }
551}
552
553#include <stdio.h>
554
555void PowerchordBase::tuner_simulation_cb(){
556 if (simulation_x < -10 || simulation_x > 10){
557 simulation_v = (simulation_v/2)-(simulation_x/5);
558 }
559
560 simulation_x += simulation_v;
561 simulation_iter++;
562
563 if (simulation_x > 50){
564 simulation_x = 50;
565 }
566
567 if (simulation_x < -50){
568 simulation_x = -50;
569 }
570
571 if (simulation_iter > 50){
572 simulation_timer->stop();
573 emit frequency_change(0);
574 tuner_pic1->setPixmap( image6 );
575 }else{
576 emit frequency_change(simulation_x);
577 }
578}
579
580/*
581 * Destroys the object and frees any allocated resources
582 */
583PowerchordBase::~PowerchordBase()
584{
585 // no need to delete child widgets, Qt does it all for us
586}
587
588void PowerchordBase::change_handler()
589{
590 qWarning( "PowerchordBase::change_handler(): Not implemented yet!" );
591}
592