/*! \brief Handle a mouse click on this piano display view * * We first determine the key number using the getKeyFromMouse() method. * * If we're below the 'root key selection' area, * we set the volume of the note to be proportional to the vertical * position on the keyboard - lower down the key is louder, within the * boundaries of the (white or black) key pressed. We then tell the * instrument to play that note, scaling for MIDI max loudness = 127. * * If we're in the 'root key selection' area, of course, we set the * root key to be that key. * * We finally update ourselves to show the key press * * \param _me the mouse click to handle. */ void PianoView::mousePressEvent( QMouseEvent * _me ) { if( _me->button() == Qt::LeftButton && m_piano != NULL ) { // get pressed key Uint32 key_num = getKeyFromMouse( _me->pos() ); if( _me->pos().y() > PIANO_BASE ) { int y_diff = _me->pos().y() - PIANO_BASE; int velocity = (int)( ( float ) y_diff / ( ( KEY_ORDER[key_num % KeysPerOctave] == Piano::WhiteKey ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) * (float) MidiMaxVelocity ); if( y_diff < 0 ) { velocity = 0; } else if( y_diff > ( ( KEY_ORDER[key_num % KeysPerOctave] == Piano::WhiteKey ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) ) { velocity = MidiMaxVelocity; } // set note on m_piano->m_midiEvProc->processInEvent( midiEvent( MidiNoteOn, 0, key_num, velocity ), midiTime() ); m_piano->m_pressedKeys[key_num] = true; m_lastKey = key_num; emit keyPressed( key_num ); } else { if( _me->modifiers() & Qt::ControlModifier ) { new stringPairDrag( "automatable_model", QString::number( m_piano-> m_midiEvProc-> baseNoteModel()->id() ), QPixmap(), this ); _me->accept(); } else { m_piano->m_midiEvProc-> baseNoteModel()-> setInitValue( (float) key_num ); emit baseNoteChanged(); } } // and let the user see that he pressed a key... :) update(); } }
/*! \brief Handle a mouse click on this piano display view * * We first determine the key number using the getKeyFromMouse() method. * * If we're below the 'root key selection' area, * we set the volume of the note to be proportional to the vertical * position on the keyboard - lower down the key is louder, within the * boundaries of the (white or black) key pressed. We then tell the * instrument to play that note, scaling for MIDI max loudness = 127. * * If we're in the 'root key selection' area, of course, we set the * root key to be that key. * * We finally update ourselves to show the key press * * \param _me the mouse click to handle. */ void PianoView::mousePressEvent( QMouseEvent * _me ) { if( _me->button() == Qt::LeftButton && m_piano != NULL ) { // get pressed key int key_num = getKeyFromMouse( _me->pos() ); if( _me->pos().y() > PIANO_BASE ) { int y_diff = _me->pos().y() - PIANO_BASE; int velocity = (int)( ( float ) y_diff / ( Piano::isWhiteKey( key_num ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) * (float) m_piano->instrumentTrack()->midiPort()->baseVelocity() ); if( y_diff < 0 ) { velocity = 0; } else if( y_diff > ( Piano::isWhiteKey( key_num ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) ) { velocity = m_piano->instrumentTrack()->midiPort()->baseVelocity(); } // set note on m_piano->midiEventProcessor()->processInEvent( MidiEvent( MidiNoteOn, -1, key_num, velocity ) ); m_piano->setKeyState( key_num, true ); m_lastKey = key_num; emit keyPressed( key_num ); } else { if( _me->modifiers() & Qt::ControlModifier ) { new StringPairDrag( "automatable_model", QString::number( m_piano->instrumentTrack()->baseNoteModel()->id() ), QPixmap(), this ); _me->accept(); } else { m_piano->instrumentTrack()->baseNoteModel()->setInitValue( (float) key_num ); emit baseNoteChanged(); } } // and let the user see that he pressed a key... :) update(); } }
setupDialogMCL::setupDialogMCL( setupDialog * _parent ) : m_parent( _parent ), m_keysActive( true ), m_mep(), m_pianoModel( &m_mep ) { setWindowTitle( tr( "New action" ) ); setModal( true ); resize( 270, 330 ); // ok/cancel buttons QWidget * buttons = new QWidget( this ); QHBoxLayout * buttonLayout = new QHBoxLayout( buttons ); buttonLayout->setSpacing( 0 ); buttonLayout->setMargin( 0 ); QPushButton * okButton = new QPushButton( embed::getIconPixmap( "apply" ), tr( "OK" ), buttons ); connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); QPushButton * cancelButton = new QPushButton( embed::getIconPixmap( "cancel" ), tr( "Cancel" ), buttons ); connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); buttonLayout->addStretch(); buttonLayout->addSpacing( 10 ); buttonLayout->addWidget( okButton ); buttonLayout->addSpacing( 10 ); buttonLayout->addWidget( cancelButton ); buttonLayout->addSpacing( 10 ); // container for settings, right above buttons QWidget * settings = new QWidget( this ); settings->setGeometry( 10, 10, 280, 100 ); // put window together QVBoxLayout * vlayout = new QVBoxLayout( this ); vlayout->setSpacing( 0 ); vlayout->setMargin( 0 ); vlayout->addWidget( settings ); vlayout->addSpacing( 10 ); vlayout->addWidget( buttons ); vlayout->addSpacing( 10 ); vlayout->addStretch(); // keyboard group m_actionKeyGroupBox = new groupBox( tr( "MIDI KEYBOARD" ), settings ); m_actionKeyGroupBox->setFixedHeight( 160 ); m_actionKeyGroupBox->ledButton()->setChecked( m_keysActive ); connect( m_actionKeyGroupBox->ledButton(), SIGNAL( clicked() ), this, SLOT( clickedKeyBox() ) ); // controller group m_actionControllerGroupBox = new groupBox( tr( "MIDI CONTROLLER" ), settings ); m_actionControllerGroupBox->setFixedHeight( 100 ); m_actionControllerGroupBox->ledButton()->setChecked( ! m_keysActive ); connect( m_actionControllerGroupBox->ledButton(), SIGNAL( clicked() ), this, SLOT( clickedControllerBox() ) ); // put settings box together QVBoxLayout * settingsLayout = new QVBoxLayout( settings ); settingsLayout->setSpacing( 0 ); settingsLayout->setMargin( 0 ); settingsLayout->addWidget( m_actionControllerGroupBox ); settingsLayout->addSpacing( 10 ); settingsLayout->addWidget( m_actionKeyGroupBox ); settingsLayout->addSpacing( 10 ); settingsLayout->addStretch(); // populate keys box m_actionsKeyBox = new QComboBox( m_actionKeyGroupBox ); m_actionsKeyBox->setGeometry( 10, 20, 150, 22 ); for( int i = 0; i < MidiControlListener::NumActions; ++i ) { MidiControlListener::ActionNameMap action = MidiControlListener::action2ActionNameMap( (MidiControlListener::EventAction) i ); if( !action.name.isEmpty() ) { m_actionsKeyBox->addItem( action.name ); } } connect( m_actionsKeyBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( clickedKeyBox() ) ); QWidget * pianoWidget = new QWidget( m_actionKeyGroupBox ); pianoWidget->move( 10, 60 ); PianoView * pianoViewWidget = new PianoView( pianoWidget ); pianoViewWidget->setFixedSize( 250, 84 ); pianoViewWidget->setModel( &m_pianoModel ); m_mep.baseNoteModel()->setValue( 60 ); m_mep.setUpdateBaseNote( true ); connect( pianoViewWidget, SIGNAL( keyPressed( int ) ), this, SLOT( clickedKeyBox() ) ); connect( pianoViewWidget, SIGNAL( baseNoteChanged() ), this, SLOT( clickedKeyBox() ) ); // populate controller box m_actionsControllerBox = new QComboBox( m_actionControllerGroupBox ); m_actionsControllerBox->setGeometry( 10, 30, 150, 22 ); for( int i = 0; i < MidiControlListener::NumActions; ++i ) { MidiControlListener::ActionNameMap action = MidiControlListener::action2ActionNameMap( (MidiControlListener::EventAction) i ); if( !action.name.isEmpty() && action.action != MidiControlListener::ActionControl ) { m_actionsControllerBox->addItem( action.name ); } } connect( m_actionsControllerBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( clickedControllerBox() ) ); m_controllerSbModel = new lcdSpinBoxModel( /* this */ ); m_controllerSbModel->setRange( 0, 127 ); m_controllerSbModel->setStep( 1 ); m_controllerSbModel->setValue( 23 ); lcdSpinBox * controllerSb = new lcdSpinBox( 3, m_actionControllerGroupBox ); controllerSb->setModel( m_controllerSbModel ); controllerSb->setLabel( tr( "CONTROLLER" ) ); controllerSb->move( 20, 60 ); connect( controllerSb, SIGNAL( manualChange() ), this, SLOT( clickedControllerBox() ) ); // widgets setup done show(); }