Example #1
0
MainWindow::MainWindow(JackSequencerController *sequencerController, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    m_sequencerController( sequencerController )
{
    ui->setupUi(this);
    connect( ui->playButton, SIGNAL(clicked()), m_sequencerController, SLOT( play() ) );
    connect( ui->stopButton, SIGNAL( clicked() ), m_sequencerController, SLOT( stop() ) );
    setFixedSize( 600, 400 );

    ui->tabWidget->setTabText( 0, QString( "Sequencer" ) );
    ui->tabWidget->setTabText( 1, QString( "Note Editor" ) );
    ui->tabWidget->setTabText( 2, tr( "Save to WAV" ) );

    // set up the combo box for waveform swapping
    QComboBox * comboBox = ui->waveformChooser;
    comboBox->addItem( m_sine );
    comboBox->addItem( m_triangle );
    comboBox->addItem( m_rsaw );
    comboBox->addItem( m_fm );

    // connect up the button pressed slots to the buttons
    connect( ui->noteOneButton, SIGNAL( clicked() ), this, SLOT( buttonOnePressed() ) );
    connect( ui->noteTwoButton, SIGNAL( clicked() ), this, SLOT( buttonTwoPressed() ) );
    connect( ui->noteThreeButton, SIGNAL( clicked() ), this, SLOT( buttonThreePressed() ) );
    connect( ui->noteFourButton, SIGNAL( clicked() ), this, SLOT( buttonFourPressed() ) );
    connect( ui->noteFiveButton, SIGNAL( clicked() ), this, SLOT( buttonFivePressed() ) );
    connect( ui->noteSixButton, SIGNAL( clicked() ), this, SLOT( buttonSixPressed() ) );

    // connect up the waveform parameter changing slots to the corresponding widgets
    connect( ui->amplitudeSlider, SIGNAL( sliderMoved(int) ), this, SLOT( amplitudeSliderChanged(int) ) );
    connect( ui->frequencySpinner, SIGNAL( valueChanged(double) ), this, SLOT( frequencySpinnerChanged(double) ) );
    connect( ui->modIndexSpinner, SIGNAL( valueChanged(double) ), this, SLOT( modulationIndexSpinnerChanged(double) ) );
    connect( ui->harmonicitySpinner, SIGNAL( valueChanged(double) ), this, SLOT( harmonicitySpinnerChanged(double) ) );
    connect( ui->waveformChooser, SIGNAL( currentIndexChanged(QString) ), this, SLOT( waveformChooserChanged(QString) ) );
    connect( m_sequencerController, SIGNAL( parametersChanged() ), this, SLOT( parametersChanged() ) );
    connect( ui->bpmBox, SIGNAL( valueChanged(int) ), m_sequencerController, SLOT( setBpm(int) ) );

    ui->bpmBox->setValue( m_sequencerController->getBpm() );

    // connect up saving features
    connect( ui->chooseButton, SIGNAL( clicked() ), this, SLOT( chooseFilename() ) );
    connect( ui->saveButton, SIGNAL( clicked() ), this, SLOT( saveWav() ) );
    connect( &m_builder, SIGNAL( writeSucceeded() ), this, SLOT( saveSuccess() ) );
    connect( &m_builder, SIGNAL( writeFailed() ), this, SLOT( saveFailure() ) );

    // Set up the sequencer grid
    for( int i = 0; i < m_sequencerController->getSequencer()->getBarLength(); i++ ) {
        // add a radio button to each list
        m_noteOneButtons.append( new QCheckBox() );
        m_noteTwoButtons.append( new QCheckBox() );
        m_noteThreeButtons.append(new QCheckBox() );
        m_noteFourButtons.append( new QCheckBox() );
        m_noteFiveButtons.append( new QCheckBox() );
        m_noteSixButtons.append( new QCheckBox() );

        // add to Gridlayout here
        ui->sequencerLayout->addWidget( m_noteOneButtons.at( i ), 5, i, Qt::AlignHCenter | Qt::AlignVCenter );
        ui->sequencerLayout->addWidget( m_noteTwoButtons.at( i ), 4, i, Qt::AlignHCenter | Qt::AlignVCenter );
        ui->sequencerLayout->addWidget( m_noteThreeButtons.at( i ), 3, i, Qt::AlignHCenter | Qt::AlignVCenter );
        ui->sequencerLayout->addWidget( m_noteFourButtons.at( i ), 2, i, Qt::AlignHCenter | Qt::AlignVCenter );
        ui->sequencerLayout->addWidget( m_noteFiveButtons.at( i ), 1, i, Qt::AlignHCenter | Qt::AlignVCenter );
        ui->sequencerLayout->addWidget( m_noteSixButtons.at( i ), 0, i, Qt::AlignHCenter | Qt::AlignVCenter );

        // connect up radio buttons to appropriate slot
        connect( m_noteOneButtons.at( i ), SIGNAL( clicked() ), this, SLOT( setNoteOneBeats() ) );
        connect( m_noteTwoButtons.at( i ), SIGNAL( clicked() ), this, SLOT( setNoteTwoBeats() ) );
        connect( m_noteThreeButtons.at( i ), SIGNAL( clicked() ), this, SLOT( setNoteThreeBeats() ) );
        connect( m_noteFourButtons.at( i ), SIGNAL( clicked() ), this, SLOT( setNoteFourBeats() ) );
        connect( m_noteFiveButtons.at( i ), SIGNAL( clicked() ), this, SLOT( setNoteFiveBeats() ) );
        connect( m_noteSixButtons.at( i ), SIGNAL( clicked() ), this, SLOT( setNoteSixBeats() ) );
    }
}