Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

powerchordbase.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Form implementation generated from reading ui file 'powerchordbase.ui'
00003 **
00004 ** Created: Sun Jan 13 23:05:11 2002
00005 **      by:  The User Interface Compiler (uic)
00006 **
00007 ** WARNING! All changes made in this file will be lost!
00008 ****************************************************************************/
00009 #include "powerchordbase.h"
00010 #include "fretboard.h"
00011 #include "vumeter.h"
00012 
00013 /* OPIE */
00014 #include <opie2/odebug.h>
00015 #include <opie2/oresource.h>
00016 using namespace Opie::Core;
00017 
00018 /* QT */
00019 #include <qbitmap.h>
00020 #include <qcombobox.h>
00021 #include <qlabel.h>
00022 #include <qlistbox.h>
00023 #include <qpushbutton.h>
00024 #include <qspinbox.h>
00025 #include <qtabwidget.h>
00026 #include <qlayout.h>
00027 #include <qtooltip.h>
00028 
00029 /*
00030  *  Constructs a PowerchordBase which is a child of 'parent', with the
00031  *  name 'name' and widget flags set to 'f'
00032  */
00033 PowerchordBase::PowerchordBase( QWidget* parent,  const char* name, WFlags fl )
00034     : QWidget( parent, name, fl )
00035 {
00036   simulation_timer = 0;
00037   audio_timer = 0;
00038 
00039   //    setPalette( QPalette( QColor( 232, 227, 215) ) );
00040 
00041   //  QPixmap image0(QString("/opt/Qtopia/pics/powerchord/image0"));
00042   QPixmap image1 = Opie::Core::OResource::loadPixmap( "powerchord/image1");
00043   QPixmap image2 = Opie::Core::OResource::loadPixmap( "powerchord/image2");
00044   QPixmap image3 = Opie::Core::OResource::loadPixmap( "powerchord/image3");
00045   QPixmap image4 = Opie::Core::OResource::loadPixmap( "powerchord/image4");
00046   QPixmap image5 = Opie::Core::OResource::loadPixmap( "powerchord/image5");
00047   image6 = Opie::Core::OResource::loadPixmap( "powerchord/image6");
00048   image_open = Opie::Core::OResource::loadPixmap( "powerchord/image_open");
00049 
00050   //  image0.setMask(image0.createHeuristicMask());
00051    image1.setMask(image1.createHeuristicMask());
00052     //    image2.setMask(image2.createHeuristicMask());
00053     //    image3.setMask(image3.createHeuristicMask());
00054     //    image4.setMask(image4.createHeuristicMask());
00055     //    image5.setMask(image5.createHeuristicMask());
00056     //    image6->setMask(image6->createHeuristicMask());
00057     //    image_open->setMask(image_open->createHeuristicMask());
00058 
00059     if ( !name )
00060         setName( "PowerchordBase" );
00061     resize( 240, 284 );
00062     setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, sizePolicy().hasHeightForWidth() ) );
00063     setMinimumSize( QSize( 240, 284 ) );
00064     setMaximumSize( QSize( 240, 284 ) );
00065     setCaption( tr( "Powerchord" ) );
00066 
00067     tabs = new QTabWidget( this, "tabs" );
00068     tabs->setEnabled( TRUE );
00069     tabs->setGeometry( QRect( 0, 0, 240, 286 ) ); 
00070     tabs->setTabPosition( QTabWidget::Bottom );
00071 
00072     tab = new QWidget( tabs, "tab" );
00073 
00074     chordkey = new QComboBox( FALSE, tab, "chordkey" );
00075     chordkey->insertItem( tr( "maj" ) );
00076     chordkey->insertItem( tr( "min" ) );
00077     chordkey->insertItem( tr( "7th" ) );
00078     chordkey->insertItem( tr( "m7" ) );
00079     chordkey->insertItem( tr( "maj7" ) );
00080     chordkey->insertItem( tr( "6th" ) );
00081     chordkey->insertItem( tr( "m6th" ) );
00082     chordkey->insertItem( tr( "aug" ) );
00083     chordkey->insertItem( tr( "dim" ) );
00084     chordkey->insertItem( tr( "sus4" ) );
00085     chordkey->insertItem( tr( "7sus4" ) );
00086     chordkey->insertItem( tr( "9th" ) );
00087     chordkey->insertItem( tr( "add9" ) );
00088     chordkey->insertItem( tr( "m9th" ) );
00089     chordkey->insertItem( tr( "maj9" ) );
00090     chordkey->insertItem( tr( "sus2" ) );
00091     chordkey->insertItem( tr( "7sus2" ) );
00092     chordkey->insertItem( tr( "11th" ) );
00093     chordkey->insertItem( tr( "m11th" ) );
00094     chordkey->insertItem( tr( "13th" ) );
00095     chordkey->insertItem( tr( "m13th" ) );
00096     chordkey->insertItem( tr( "maj13" ) );
00097     chordkey->insertItem( tr( "6/9" ) );
00098     chordkey->insertItem( tr( "flat5" ) );
00099     chordkey->insertItem( tr( "7#9" ) );
00100     chordkey->insertItem( tr( QString::fromUtf8( "ø7" ) ) );
00101     chordkey->insertItem( tr( "5" ) );
00102     chordkey->setGeometry( QRect( 40, 0, 51, 21 ) ); 
00103 
00104     chordfret = new QComboBox( FALSE, tab, "chordfret" );
00105     chordfret->insertItem( tr( "open" ) );
00106     chordfret->insertItem( tr( "1st" ) );
00107     chordfret->insertItem( tr( "2nd" ) );
00108     chordfret->insertItem( tr( "3rd" ) );
00109     chordfret->insertItem( tr( "4th" ) );
00110     chordfret->insertItem( tr( "5th" ) );
00111     chordfret->insertItem( tr( "6th" ) );
00112     chordfret->insertItem( tr( "7th" ) );
00113     chordfret->insertItem( tr( "8th" ) );
00114     chordfret->insertItem( tr( "9th" ) );
00115     chordfret->insertItem( tr( "10th" ) );
00116     chordfret->insertItem( tr( "11th" ) );
00117     chordfret->insertItem( tr( "12th" ) );
00118     chordfret->insertItem( tr( "13th" ) );
00119     chordfret->insertItem( tr( "14th" ) );
00120     chordfret->insertItem( tr( "15th" ) );
00121     chordfret->insertItem( tr( "16th" ) );
00122     chordfret->setGeometry( QRect( 90, 0, 55, 21 ) ); //cxm less 5 width
00123 
00124     chordnote = new QComboBox( FALSE, tab, "chordnote" );
00125     chordnote->insertItem( tr( "C" ) );
00126     chordnote->insertItem( tr( "C#" ) );
00127     chordnote->insertItem( tr( "D" ) );
00128     chordnote->insertItem( tr( "Eb" ) );
00129     chordnote->insertItem( tr( "E" ) );
00130     chordnote->insertItem( tr( "F" ) );
00131     chordnote->insertItem( tr( "F#" ) );
00132     chordnote->insertItem( tr( "G" ) );
00133     chordnote->insertItem( tr( "G#" ) );
00134     chordnote->insertItem( tr( "A" ) );
00135     chordnote->insertItem( tr( "Bb" ) );
00136     chordnote->insertItem( tr( "B" ) );
00137     chordnote->setGeometry( QRect( 0, 0, 40, 21 ) ); 
00138     chordnote->setCurrentItem( 9 );
00139 
00140     QWidget* privateLayoutWidget = new QWidget( tab, "Layout1" );
00141     privateLayoutWidget->setGeometry( QRect( 5, 232, 160, 20 ) ); 
00142     Layout1 = new QHBoxLayout( privateLayoutWidget ); 
00143     Layout1->setSpacing( 6 );
00144     Layout1->setMargin( 0 );
00145 
00146     s1_1 = new QLabel( privateLayoutWidget, "s1_1" );
00147     s1_1->setText( tr( "E" ) );
00148     s1_1->setAlignment( int( QLabel::AlignCenter ) );
00149     Layout1->addWidget( s1_1 );
00150 
00151     s1_2 = new QLabel( privateLayoutWidget, "s1_2" );
00152     s1_2->setText( tr( "A" ) );
00153     s1_2->setAlignment( int( QLabel::AlignCenter ) );
00154     Layout1->addWidget( s1_2 );
00155 
00156     s1_3 = new QLabel( privateLayoutWidget, "s1_3" );
00157     s1_3->setText( tr( "E" ) );
00158     s1_3->setAlignment( int( QLabel::AlignCenter ) );
00159     Layout1->addWidget( s1_3 );
00160 
00161     s1_4 = new QLabel( privateLayoutWidget, "s1_4" );
00162     s1_4->setText( tr( "A" ) );
00163     s1_4->setAlignment( int( QLabel::AlignCenter ) );
00164     Layout1->addWidget( s1_4 );
00165 
00166     s1_5 = new QLabel( privateLayoutWidget, "s1_5" );
00167     s1_5->setText( tr( "C#" ) );
00168     s1_5->setAlignment( int( QLabel::AlignCenter ) );
00169     Layout1->addWidget( s1_5 );
00170 
00171     s1_6 = new QLabel( privateLayoutWidget, "s1_6" );
00172     s1_6->setText( tr( "E" ) );
00173     s1_6->setAlignment( int( QLabel::AlignCenter ) );
00174     Layout1->addWidget( s1_6 );
00175 
00176     //    sound_label = new QLabel( tab, "sound_label" );
00177     //    sound_label->setGeometry( QRect( 185, 160, 32, 17 ) ); 
00178     //    sound_label->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sound_label->sizePolicy().hasHeightForWidth() ) );
00179     //    sound_label->setPixmap( image0 );
00180     //    sound_label->pixmap()->setMask(*image0.mask());
00181     //    sound_label->setScaledContents( TRUE );
00182     //  sound_label->setBackgroundMode( QWidget::PaletteButton );
00183     //    sound_label->setBackgroundColor(this->backgroundColor());
00184     //    sound_label->setPalette( QPalette( QColor( 232, 227, 215) ) );
00185 
00186 
00187     Frame6 = new QFrame( tab, "Frame6" );
00188     Frame6->setGeometry( QRect( 170, 145, 66, 10 ) ); 
00189     Frame6->setFrameShape( QFrame::HLine );
00190     Frame6->setFrameShadow( QFrame::Raised );
00191 
00192     chordshow_label = new QLabel( tab, "chordshow_label" );
00193     chordshow_label->setGeometry( QRect( 185, 60, 32, 17 ) ); 
00194     //    chordshow_label->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, chordshow_label->sizePolicy().hasHeightForWidth() ) );
00195     chordshow_label->setFrameShape( QLabel::NoFrame );
00196     chordshow_label->setPixmap( image1 );
00197     chordshow_label->setScaledContents( TRUE );
00198     //    chordshow_label->setBackgroundMode( QWidget::PaletteButton );
00199 
00200     transport_rec = new QPushButton( tab, "transport_rec" );
00201     transport_rec->setGeometry( QRect( 170, 80, 30, 30 ) ); 
00202     transport_rec->setText( "" );
00203     transport_rec->setPixmap( image2 );
00204 
00205     play_sound = new QPushButton( tab, "play_sound" );
00206     play_sound->setGeometry( QRect( 170, 180, 60, 55 ) ); 
00207     play_sound->setText( "" );
00208     play_sound->setPixmap( image3 );
00209 
00210     Frame6_2 = new QFrame( tab, "Frame6_2" );
00211     Frame6_2->setGeometry( QRect( 170, 45, 66, 10 ) ); 
00212     Frame6_2->setFrameShape( QFrame::HLine );
00213     Frame6_2->setFrameShadow( QFrame::Raised );
00214 
00215     transport_play = new QPushButton( tab, "transport_play" );
00216     transport_play->setEnabled( FALSE );
00217     transport_play->setGeometry( QRect( 200, 80, 30, 30 ) ); 
00218     transport_play->setText( "" );
00219     transport_play->setPixmap( image3 );
00220 
00221     transport_rew = new QPushButton( tab, "transport_rew" );
00222     transport_rew->setEnabled( FALSE );
00223     transport_rew->setGeometry( QRect( 170, 110, 30, 30 ) ); 
00224     transport_rew->setText( "" );
00225     transport_rew->setPixmap( image4 );
00226 
00227     transport_fwd = new QPushButton( tab, "transport_fwd" );
00228     transport_fwd->setEnabled( FALSE );
00229     transport_fwd->setGeometry( QRect( 200, 110, 30, 30 ) ); 
00230     transport_fwd->setText( "" );
00231     transport_fwd->setPixmap( image5 );
00232 
00233     chordname = new QLabel( tab, "chordname" );
00234     chordname->setGeometry( QRect( 146, 0, 90, 20 ) ); //cxm moved l 5
00235     chordname->setText( tr( "A" ) );
00236     chordname->setAlignment( int( QLabel::AlignCenter ) );
00237     QToolTip::add(  chordname, "" );
00238 
00239     synth = new gs();
00240     tuner = new gt();
00241     frets = new FretBoard( tab, "frets" );
00242     frets->setGeometry( QRect( 0, 20, 168, 210 ) ); 
00243     tabs->insertTab( tab, tr( "Guitar" ) );
00244 
00245     tab_2 = new QWidget( tabs, "tab_2" );
00246 
00247     optlab2 = new QLabel( tab_2, "optlab2" );
00248     optlab2->setGeometry( QRect( 9, 58, 120, 41 ) ); 
00249     optlab2->setText( tr( "Alternative tunings are possible" ) );
00250     optlab2->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter | QLabel::AlignLeft ) );
00251 
00252     span = new QComboBox( FALSE, tab_2, "span" );
00253     span->insertItem( tr( "2" ) );
00254     span->insertItem( tr( "3" ) );
00255     span->insertItem( tr( "4" ) );
00256     span->insertItem( tr( "5" ) );
00257     span->insertItem( tr( "6" ) );
00258     span->setGeometry( QRect( 180, 20, 50, 21 ) ); 
00259     span->setCurrentItem( 1 );
00260 
00261     TextLabel1 = new QLabel( tab_2, "TextLabel1" );
00262     TextLabel1->setGeometry( QRect( 3, 109, 226, 140 ) ); 
00263     TextLabel1->setText( tr( QString::fromUtf8( "©2002 Camilo Mesias\n"
00264 "camilo@mesias.co.uk\n"
00265 "Version 0.0.7 beta" ) ) );
00266     TextLabel1->setAlignment( int( QLabel::AlignBottom | QLabel::AlignLeft ) );
00267 
00268     tuning = new QComboBox( FALSE, tab_2, "tuning" );
00269     tuning->insertItem( tr( "EADGBE" ) );
00270     tuning->insertItem( tr( "EBEG#BE" ) );
00271     tuning->insertItem( tr( "EAEAC#E" ) );
00272     tuning->insertItem( tr( "EADF#BE" ) );
00273     tuning->insertItem( tr( "EADGCF" ) );
00274     tuning->insertItem( tr( "DADGAD" ) );
00275     tuning->insertItem( tr( "DGCGCD" ) );
00276     tuning->insertItem( tr( "DADF#AD" ) );
00277     tuning->insertItem( tr( "DADGBE" ) );
00278     tuning->insertItem( tr( "DGDGBD" ) );
00279     tuning->insertItem( tr( "DADACD" ) );
00280     tuning->insertItem( tr( "CGCGAE" ) );
00281     tuning->insertItem( tr( "FADGBE" ) );
00282     tuning->insertItem( tr( "G minor" ) );
00283     tuning->setGeometry( QRect( 140, 70, 91, 21 ) ); 
00284 
00285     optlab1 = new QLabel( tab_2, "optlab1" );
00286     optlab1->setGeometry( QRect( 8, 8, 160, 40 ) ); 
00287     optlab1->setText( tr( "Span: the greatest number of frets over which you want chords to be generated" ) );
00288     optlab1->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter | QLabel::AlignLeft ) );
00289     tabs->insertTab( tab_2, tr( "Options" ) );
00290 
00291     Tuner = new QWidget( tabs, "Tuner" );
00292 
00293     Frame4 = new QFrame( Tuner, "Frame4" );
00294     Frame4->setGeometry( QRect( 0, 0, 230, 126 ) ); 
00295     Frame4->setFrameShape( QFrame::Box );
00296     Frame4->setFrameShadow( QFrame::Raised );
00297 
00298     vu = new VUMeter( Frame4, "vu" );
00299     vu->setGeometry( QRect( 5, 5, 220, 115 ) ); 
00300 
00301     tuner_note = new QComboBox( FALSE, Tuner, "tuner_note" );
00302     tuner_note->insertItem( tr( "auto" ) );
00303     tuner_note->insertItem( tr( "E" ) );
00304     tuner_note->insertItem( tr( "D" ) );
00305     tuner_note->insertItem( tr( "G" ) );
00306     tuner_note->insertItem( tr( "A" ) );
00307     tuner_note->insertItem( tr( "B" ) );
00308     tuner_note->insertItem( tr( "C" ) );
00309     tuner_note->insertItem( tr( "F" ) );
00310     tuner_note->setGeometry( QRect( 5, 160, 90, 20 ) ); 
00311 
00312     Frame8 = new QFrame( Tuner, "Frame8" );
00313     Frame8->setGeometry( QRect( -2, 188, 231, 10 ) ); 
00314     Frame8->setFrameShape( QFrame::HLine );
00315     Frame8->setFrameShadow( QFrame::Raised );
00316 
00317     tuner_start = new QPushButton( Tuner, "tuner_start" );
00318     tuner_start->setGeometry( QRect( 100, 155, 91, 30 ) ); 
00319     tuner_start->setText( tr( "Start" ) );
00320 
00321     tuner_lab1 = new QLabel( Tuner, "tuner_lab1" );
00322     tuner_lab1->setGeometry( QRect( 10, 130, 100, 21 ) ); 
00323     tuner_lab1->setText( tr( "Tuner operation" ) );
00324 
00325     tuner_lab2 = new QLabel( Tuner, "tuner_lab2" );
00326     tuner_lab2->setGeometry( QRect( 10, 200, 100, 16 ) ); 
00327     tuner_lab2->setText( tr( "Pitch calibration" ) );
00328 
00329     tuner_calib_note = new QComboBox( FALSE, Tuner, "tuner_calib_note" );
00330     tuner_calib_note->insertItem( tr( "A" ) );
00331     tuner_calib_note->insertItem( tr( "C" ) );
00332     tuner_calib_note->setGeometry( QRect( 5, 225, 90, 21 ) ); 
00333 
00334     tuner_calib_freq = new QSpinBox( Tuner, "tuner_calib_freq" );
00335     tuner_calib_freq->setGeometry( QRect( 105, 225, 71, 21 ) ); 
00336     tuner_calib_freq->setSuffix( tr( "Hz" ) );
00337     tuner_calib_freq->setWrapping( TRUE );
00338     tuner_calib_freq->setMaxValue( 500 );
00339     tuner_calib_freq->setMinValue( 300 );
00340     tuner_calib_freq->setValue( 440 );
00341 
00342     tuner_lab3 = new QLabel( Tuner, "tuner_lab3" );
00343     tuner_lab3->setGeometry( QRect( 185, 225, 40, 21 ) ); 
00344     tuner_lab3->setText( tr( "Pitch" ) );
00345 
00346     tuner_pic1 = new QLabel( Tuner, "tuner_pic1" );
00347     tuner_pic1->setGeometry( QRect( 195, 155, 31, 31 ) ); 
00348     tuner_pic1->setFrameShape( QLabel::NoFrame );
00349     tuner_pic1->setPixmap( image6 );
00350     tuner_pic1->setScaledContents( TRUE );
00351     tabs->insertTab( Tuner, tr( "Tuner" ) );
00352 
00353     tab_3 = new QWidget( tabs, "tab_3" );
00354 
00355     chordlistlab1 = new QLabel( tab_3, "chordlistlab1" );
00356     chordlistlab1->setGeometry( QRect( 5, 5, 216, 16 ) );
00357     chordlistlab1->setText( tr( "Chord list" ) );
00358 
00359     chordlist = new QListBox( tab_3, "chordlist" );
00360     chordlist->setGeometry( QRect( 5, 25, 220, 200 ) );
00361 
00362     list_remove_btn = new QPushButton( tab_3, "list_remove_btn" );
00363     list_remove_btn->setGeometry( QRect( 150, 230, 71, 25 ) );
00364     list_remove_btn->setText( tr( "Remove" ) );
00365     tabs->insertTab( tab_3, tr( "Chords" ) );
00366 
00367     // hope this does what it's supposed to!!
00368     //    setPalette( QPalette( QColor( 232, 227, 215) ) );
00369     
00370     // signals and slots connections
00371 
00372     //cxm
00373     connect( tuning, SIGNAL( activated(int) ), frets, SLOT( Tune(int) ) );
00374     connect( span, SIGNAL( activated(int) ), frets, SLOT( Span(int) ) );
00375     connect( transport_rec, SIGNAL( clicked() ), this, SLOT( transport_rec_cb() ));
00376     connect( play_sound, SIGNAL( clicked() ), this, SLOT( play_chord_cb() ));
00377     connect( tuner_start, SIGNAL( clicked() ), this, SLOT( tuner_start_cb() ));
00378     connect( tuner_note, SIGNAL( textChanged(const QString&) ), vu, SLOT( AnnotL(const QString&) ));
00379     connect( this, SIGNAL( frequency_change(int) ), vu, SLOT( Value(int) ));
00380 
00381     connect( chordnote, SIGNAL( activated(int) ), frets, SLOT( Base(int) ) );
00382     connect( chordkey, SIGNAL( activated(int) ), frets, SLOT( Chord(int) ) );
00383     connect( chordfret, SIGNAL( activated(int) ), frets, SLOT( Fret(int) ) );
00384     connect( list_remove_btn, SIGNAL( clicked() ), this, SLOT( list_remove_cb() ) );
00385     connect( frets, SIGNAL( s1nameChanged(const QString&) ), s1_1, SLOT( setText(const QString&) ) );
00386     connect( frets, SIGNAL( s2nameChanged(const QString&) ), s1_2, SLOT( setText(const QString&) ) );
00387     connect( frets, SIGNAL( s3nameChanged(const QString&) ), s1_3, SLOT( setText(const QString&) ) );
00388     connect( frets, SIGNAL( s4nameChanged(const QString&) ), s1_4, SLOT( setText(const QString&) ) );
00389     connect( frets, SIGNAL( s5nameChanged(const QString&) ), s1_5, SLOT( setText(const QString&) ) );
00390     connect( frets, SIGNAL( s6nameChanged(const QString&) ), s1_6, SLOT( setText(const QString&) ) );
00391     connect( frets, SIGNAL( nameChanged(const QString&) ), chordname, SLOT( setText(const QString&) ) );
00392 }
00393 
00394 
00395 static int known=0;
00396 #include <qmessagebox.h>
00397 void PowerchordBase::transport_rec_cb(){
00398   chordlist->insertItem(chordname->text(),-1);
00399   if (!known){
00400     QMessageBox::information(this, tr("Powerchord"),
00401                          tr("<P>This chord has been saved into the list of chords, for later playback.<P>"));
00402     known = 1;
00403   }
00404 }
00405 void PowerchordBase::list_remove_cb(){
00406   if (chordlist->count() > 0){
00407     chordlist->removeItem(0);
00408   }
00409 }
00410 void PowerchordBase::play_chord_cb(){
00411   //    QMessageBox::information(this, "Coming soon!", "This button plays\nthe chord by synthesizing\nthe sound of the notes.");
00412 
00413 
00414     if (audio_timer){
00415       audio_timer->stop();
00416       // set pixmap?
00417       synth->Stop();
00418       delete(audio_timer);
00419       audio_timer = 0;
00420     }else{
00421       // get notes from chord engine
00422       
00423       int note;
00424       int base;
00425       int octave;
00426       note = frets->ce.noteindex(0);
00427       if (note >= 0){
00428         //      fprintf(stderr, "Note was %d\n", note);
00429         base = note % 12;
00430         octave = note / 12;
00431         synth->note_start(0, base, octave);
00432       }else{
00433         // subtle bug here - replay second note if 1st one muted
00434         note = frets->ce.noteindex(1);
00435         base = note % 12;
00436         octave = note / 12;
00437         synth->note_start(1, base, octave);
00438 
00439       }
00440 
00441       // init synth
00442       if (synth->Play()){
00443         // error
00444         QMessageBox::information(this, tr("Powerchord"),
00445                          tr("<P>Unable to open device for sound playback - check that no other application is using it.</P>"));
00446         return;
00447       }
00448       synth->fill_buffer();
00449       
00450       // start timer
00451       audio_timer = new QTimer();
00452       connect(audio_timer, SIGNAL( timeout() ), this, SLOT( audio_cb() ));
00453       // set pixmap on player?
00454       audio_timer->start(19); // 19 msec (fudge factor!!)
00455     }
00456 }
00457 
00458 
00459 
00460 void PowerchordBase::audio_cb(){
00461   // play the next bit of audio until quiet
00462 
00463   // strum timing
00464 #define INTERVAL 2
00465 
00466   if ((synth->Frames() % INTERVAL) == 0){
00467     int string = synth->Frames() / INTERVAL;
00468     if (string <= 5){
00469       int note;
00470       int base;
00471       int octave;
00472       note = frets->ce.noteindex(string);
00473       // check not muted...
00474       if (note > 0){
00475         base = note % 12;
00476         octave = note / 12;
00477         synth->note_start(string, base, octave);
00478       }
00479     }
00480   }
00481   
00482   if (synth->Playing()){
00483     synth->write_buffer();
00484     synth->fill_buffer();
00485   }else{
00486     audio_timer->stop();
00487     // set pixmap?
00488     synth->Stop();
00489     delete(audio_timer);
00490     audio_timer = 0;
00491   }
00492 }
00493 
00494 // the real tuner
00495 //  void PowerchordBase::tuner_start_cb(){
00496 
00497 //    if (tuner->Listening()){
00498 //      simulation_timer->stop();
00499 //      tuner->Stop();
00500 //      tuner_pic1->setPixmap( *image6 );
00501     
00502 //    }else{
00503 //      tuner_pic1->setPixmap( *image_open );
00504     
00505 //      if (!simulation_timer){
00506 //        simulation_timer = new QTimer();
00507       
00508       
00509 //        connect(simulation_timer, SIGNAL( timeout() ), this, SLOT( tuner_cb() ));
00510 //      }
00511     
00512 //      simulation_timer->start(50);
00513 //      tuner->Listen();
00514     
00515 //    }  
00516 //  }
00517 
00518 void PowerchordBase::tuner_cb(){
00519   if (tuner->Listening()){
00520     tuner->read_buffer();
00521     tuner->process_buffer();
00522     
00523     // update gui
00524     // do something with the note: tuner->Note()
00525     emit frequency_change(tuner->Tuning());
00526     
00527   }else{
00528     simulation_timer->stop();
00529     tuner->Stop();
00530     tuner_pic1->setPixmap( image6 );
00531   }
00532 }
00533 
00534 
00535 void PowerchordBase::tuner_start_cb(){
00536   if (0 == QMessageBox::information(this, tr("Powerchord"),
00537                                         tr("<P>Using the microphone, the note's frequency is analysed. This is a simulation.</P>"),
00538                                         tr("OK"), tr("Cancel"), 0, 1)){
00539     if (simulation_timer){
00540       simulation_timer->stop();
00541     }else{
00542       simulation_timer = new QTimer();
00543       connect(simulation_timer, SIGNAL( timeout() ), this, SLOT( tuner_simulation_cb() ));
00544       
00545     }
00546     simulation_x = -45;
00547     simulation_v = 0;
00548     simulation_iter = 0;
00549 
00550     tuner_pic1->setPixmap( image_open );
00551     simulation_timer->start(100);
00552   }
00553 }
00554 
00555 #include <stdio.h>
00556 
00557 void PowerchordBase::tuner_simulation_cb(){
00558   if (simulation_x < -10 || simulation_x > 10){
00559     simulation_v = (simulation_v/2)-(simulation_x/5);
00560   }
00561   
00562   simulation_x += simulation_v;
00563   simulation_iter++;
00564 
00565   if (simulation_x > 50){
00566     simulation_x = 50;
00567   }
00568 
00569   if (simulation_x < -50){
00570     simulation_x = -50;
00571   }
00572 
00573   if (simulation_iter > 50){
00574     simulation_timer->stop();
00575     emit frequency_change(0);
00576     tuner_pic1->setPixmap( image6 );
00577   }else{
00578     emit frequency_change(simulation_x);
00579   }
00580 }
00581 
00582 /*
00583  *  Destroys the object and frees any allocated resources
00584  */
00585 PowerchordBase::~PowerchordBase()
00586 {
00587     // no need to delete child widgets, Qt does it all for us
00588 }
00589 
00590 void PowerchordBase::change_handler()
00591 {
00592     owarn << "PowerchordBase::change_handler(): Not implemented yet!" << oendl; 
00593 }
00594 

Generated on Sat Nov 5 16:17:35 2005 for OPIE by  doxygen 1.4.2