Changeset 191

Show
Ignore:
Timestamp:
06/12/08 21:43:01 (5 years ago)
Author:
smoors
Message:

code cleanup / midiTable adds new rows automatically

Location:
trunk/gui/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/gui/src/PreferencesDialog.cpp

    r188 r191  
    378378 
    379379 
    380 /* 
    381 void PreferencesDialog::setupMidiTable() 
    382 { 
    383         actionManager *aH = actionManager::getInstance(); 
    384         midiMap *mM = midiMap::getInstance(); 
    385  
    386         QStringList items; 
    387         items << tr( "Event" ) << tr( "Param." ) << tr( "Action" ) 
    388            << tr( "Param." ); 
    389  
    390  
    391         int rowCount; 
    392          
    393         rowCount = ( mM->getMMCMap() ).size(); 
    394  
    395         tableWidget->setRowCount( 0 ); 
    396         tableWidget->setColumnCount( 4 ); 
    397  
    398         tableWidget->verticalHeader()->hide(); 
    399  
    400         tableWidget->setHorizontalHeaderLabels( items ); 
    401          
    402          
    403         tableWidget->setFixedWidth( 500 ); 
    404         tableWidget->setColumnWidth( 0 , 175 ); 
    405         tableWidget->setColumnWidth( 1, 73 ); 
    406         tableWidget->setColumnWidth( 2, 175 ); 
    407         tableWidget->setColumnWidth( 3 , 73 ); 
    408  
    409  
    410         rowCount= 0;     
    411          
    412         std::map< QString , action *> mmcMap = mM->getMMCMap(); 
    413         std::map< QString , action *>::iterator dIter(mmcMap.begin()); 
    414  
    415  
    416         for( dIter = mmcMap.begin(); dIter != mmcMap.end(); dIter++ ) 
    417         { 
    418                 tableWidget->insertRow( tableWidget->rowCount() ); 
    419                 QString eventString = dIter->first; 
    420  
    421                 QComboBox *eventBox = new QComboBox(); 
    422                 eventBox->insertItems( rowCount , aH->getEventList() ); 
    423                 eventBox->setCurrentIndex( eventBox->findText(eventString) ); 
    424                 tableWidget->setCellWidget( rowCount, 0, eventBox ); 
    425                  
    426                 QSpinBox *eventParameterSpinner = new QSpinBox(); 
    427                 tableWidget->setCellWidget( rowCount , 1, eventParameterSpinner ); 
    428  
    429                 action * pAction = mM->getMMCAction( eventString ); 
    430          
    431                 QComboBox *actionBox = new QComboBox(); 
    432                 actionBox->insertItems(rowCount,aH->getActionList()); 
    433                 actionBox->setCurrentIndex ( actionBox->findText(pAction->getType() ) ); 
    434                 tableWidget->setCellWidget( rowCount , 2, actionBox ); 
    435          
    436  
    437                 QString actionParameter; 
    438                 if( pAction->getParameterList().size() != 0 ){ 
    439                         actionParameter = pAction->getParameterList().at(0); 
    440                 } 
    441  
    442                 QSpinBox *actionParameterSpinner = new QSpinBox(); 
    443                  
    444                 bool ok; 
    445                 actionParameterSpinner->setValue( actionParameter.toInt(&ok,10) ); 
    446                  
    447                 tableWidget->setCellWidget( rowCount , 3, actionParameterSpinner ); 
    448                 rowCount++; 
    449         } 
    450  
    451         for( int note = 0; note < 128; note++ ){ 
    452                  
    453                 QString eventString = "NOTE"; 
    454                  
    455                 action * pAction = mM->getNoteAction( note ); 
    456                  
    457                 if( pAction->getType() != "NOTHING" ){ 
    458                  
    459                         tableWidget->insertRow( tableWidget->rowCount() ); 
    460                         QComboBox *eventBox = new QComboBox(); 
    461                         eventBox->insertItems( rowCount , aH->getEventList() ); 
    462                         eventBox->setCurrentIndex( eventBox->findText(eventString) ); 
    463                         tableWidget->setCellWidget( rowCount, 0, eventBox ); 
    464                          
    465                         QSpinBox *eventParameterSpinner = new QSpinBox(); 
    466                         tableWidget->setCellWidget( rowCount , 1, eventParameterSpinner ); 
    467                         eventParameterSpinner->setValue( note ); 
    468                          
    469                         QComboBox *actionBox = new QComboBox(); 
    470                         actionBox->insertItems(rowCount,aH->getActionList()); 
    471                         actionBox->setCurrentIndex ( actionBox->findText(pAction->getType() ) ); 
    472                         tableWidget->setCellWidget( rowCount , 2, actionBox ); 
    473                  
    474          
    475                         QString actionParameter; 
    476                         QSpinBox *actionParameterSpinner = new QSpinBox(); 
    477  
    478                         if( pAction->getParameterList().size() > 0 ){ 
    479                                 actionParameter = pAction->getParameterList().at(0); 
    480                                 bool ok; 
    481                                 actionParameterSpinner->setValue( actionParameter.toInt(&ok,10) ); 
    482                         } 
    483          
    484                         tableWidget->setCellWidget( rowCount , 3, actionParameterSpinner ); 
    485                         rowCount++; 
    486                 } 
    487         } 
    488          
    489         tableWidget->insertRow( tableWidget->rowCount() ); 
    490  
    491         QComboBox *eventBox = new QComboBox(); 
    492         eventBox->insertItems( rowCount , aH->getEventList() ); 
    493         tableWidget->setCellWidget( rowCount, 0, eventBox ); 
    494                  
    495         QSpinBox *eventParameterSpinner = new QSpinBox(); 
    496         eventParameterSpinner->setEnabled( false ); 
    497         tableWidget->setCellWidget( rowCount , 1, eventParameterSpinner ); 
    498  
    499         QComboBox *actionBox = new QComboBox(); 
    500         actionBox->insertItems( rowCount, aH->getActionList() ); 
    501         tableWidget->setCellWidget( rowCount, 2, actionBox ); 
    502                          
    503         QSpinBox *actionParameterSpinner = new QSpinBox(); 
    504         tableWidget->setCellWidget( rowCount, 3, actionParameterSpinner ); 
    505 } 
    506  
    507  
    508 void PreferencesDialog::saveMidiTable(){ 
    509          
    510         delete  midiMap::getInstance(); 
    511         midiMap *mM  = midiMap::getInstance(); 
    512          
    513  
    514         int row = 0; 
    515          
    516         for( row = 0; row <  tableWidget->rowCount(); row++ ){ 
    517  
    518                 QComboBox * eventCombo =  dynamic_cast <QComboBox *> ( tableWidget->cellWidget( row, 0 ) ); 
    519          
    520                 QSpinBox * eventSpinner = dynamic_cast <QSpinBox *> ( tableWidget->cellWidget( row, 1 ) ); 
    521  
    522                 QComboBox * actionCombo = dynamic_cast <QComboBox *> ( tableWidget->cellWidget( row, 2 ) ); 
    523  
    524                 QSpinBox * actionSpinner = dynamic_cast <QSpinBox *> ( tableWidget->cellWidget( row, 3 ) ); 
    525  
    526                  
    527  
    528                 QString eventString; 
    529                 QString actionString; 
    530                  
    531  
    532                 if( eventCombo->currentText() != "" && actionCombo->currentText() != "" ){ 
    533                         eventString = eventCombo->currentText(); 
    534  
    535                         actionString = actionCombo->currentText(); 
    536                  
    537                         action * pAction = new action( actionString ); 
    538  
    539                         if( actionSpinner->cleanText() != ""){ 
    540                                 pAction->addParameter( actionSpinner->cleanText() ); 
    541                         } 
    542          
    543                         if( eventString.left(3) == "MMC" ){ 
    544                                 mM->registerMMCEvent( eventString , pAction ); 
    545                         } 
    546                          
    547                         if( eventString.left(4) == "NOTE" ){ 
    548                                 mM->registerNoteEvent( eventSpinner->cleanText().toInt() , pAction ); 
    549                         } 
    550                 } 
    551         } 
    552  
    553 } 
    554 */ 
    555  
    556380void PreferencesDialog::updateDriverInfo() 
    557381{ 
  • trunk/gui/src/PreferencesDialog.h

    r188 r191  
    5555        private: 
    5656                bool m_bNeedDriverRestart; 
    57  
    58                 //void setupMidiTable(); 
    59                 //void saveMidiTable(); 
    60  
    6157                void updateDriverInfo(); 
    6258}; 
  • trunk/gui/src/widgets/midiTable.cpp

    r189 r191  
    2222 
    2323#include "midiTable.h" 
    24  
    25 #include <iostream> 
    2624 
    2725#include <hydrogen/midiMap.h> 
     
    4644        int myRow = 0; 
    4745         
    48         for( myRow = 0; myRow <  rowCount ; myRow++) 
     46        for( myRow = 0; myRow <=  rowCount ; myRow++) 
    4947        { 
    5048                delete cellWidget(myRow,0); 
     
    5553} 
    5654 
     55 
    5756void midiTable::updateTable(){ 
    5857         
    59         ERRORLOG("update"); 
    60  
    61 } 
    62  
    63 void midiTable::insertNewRow(QString eventString, int argument ) 
     58         
     59        if( (rowCount-1) > 0 )  
     60        { 
     61                QComboBox * eventCombo =  dynamic_cast <QComboBox *> ( cellWidget( rowCount-1, 0 ) ); 
     62                QComboBox * actionCombo = dynamic_cast <QComboBox *> ( cellWidget( rowCount-1, 2 ) ); 
     63 
     64                if( eventCombo == NULL or actionCombo == NULL) return; 
     65 
     66                if( actionCombo->currentText() != "" and eventCombo->currentText() != "" ){ 
     67                        insertNewRow("", "", 0, 0); 
     68                } 
     69        } 
     70} 
     71 
     72void midiTable::insertNewRow(QString actionString , QString eventString, int eventParameter , int actionParameter) 
    6473{ 
    6574        actionManager *aH = actionManager::getInstance(); 
    66         midiMap *mM = midiMap::getInstance(); 
    67          
    68         action * pAction; 
    69         int eventSpinnerValue = 0; 
    70  
    71         if ( eventString != "NOTE"){ 
    72                 pAction = mM->getMMCAction( eventString ); 
    73                 eventSpinnerValue = argument; 
    74         } else { 
    75                  pAction = mM->getNoteAction( argument ); 
    76         } 
    77  
    78         if( pAction->getType() == "NOTHING" ) return; 
    79  
    8075 
    8176        insertRow( rowCount ); 
     77         
     78        int oldRowCount = rowCount; 
     79 
     80        rowCount++; 
    8281 
    8382        QComboBox *eventBox = new QComboBox(); 
    8483        connect( eventBox , SIGNAL( currentIndexChanged( int ) ) , this , SLOT( updateTable() ) ); 
    85         eventBox->insertItems( rowCount , aH->getEventList() ); 
     84        eventBox->insertItems( oldRowCount , aH->getEventList() ); 
    8685        eventBox->setCurrentIndex( eventBox->findText(eventString) ); 
    87         setCellWidget( rowCount, 0, eventBox ); 
     86        setCellWidget( oldRowCount, 0, eventBox ); 
    8887         
    8988         
    9089        QSpinBox *eventParameterSpinner = new QSpinBox(); 
    91         setCellWidget( rowCount , 1, eventParameterSpinner ); 
    92         eventParameterSpinner->setValue( eventSpinnerValue ); 
     90        setCellWidget( oldRowCount , 1, eventParameterSpinner ); 
     91        eventParameterSpinner->setValue( eventParameter ); 
    9392 
    9493 
    9594        QComboBox *actionBox = new QComboBox(); 
    96         actionBox->insertItems(rowCount,aH->getActionList()); 
    97         actionBox->setCurrentIndex ( actionBox->findText(pAction->getType() ) ); 
    98         setCellWidget( rowCount , 2, actionBox ); 
    99          
    100  
    101         QString actionParameter; 
    102         if( pAction->getParameterList().size() != 0 ){ 
    103                 actionParameter = pAction->getParameterList().at(0); 
    104         } 
     95        actionBox->insertItems( oldRowCount, aH->getActionList()); 
     96        actionBox->setCurrentIndex ( actionBox->findText( actionString ) ); 
     97        setCellWidget( oldRowCount , 2, actionBox ); 
     98         
     99 
    105100        QSpinBox *actionParameterSpinner = new QSpinBox(); 
    106         bool ok; 
    107          
    108         setCellWidget( rowCount , 3, actionParameterSpinner ); 
    109         actionParameterSpinner->setValue( actionParameter.toInt(&ok,10) ); 
    110  
    111         rowCount++; 
     101         
     102        setCellWidget( oldRowCount , 3, actionParameterSpinner ); 
     103        actionParameterSpinner->setValue( actionParameter); 
     104 
     105 
    112106} 
    113107 
    114108void midiTable::setupMidiTable() 
    115109{ 
    116         actionManager *aH = actionManager::getInstance(); 
    117110        midiMap *mM = midiMap::getInstance(); 
    118111 
     
    136129 
    137130 
    138          
    139          
     131        bool ok; 
    140132        std::map< QString , action *> mmcMap = mM->getMMCMap(); 
    141133        std::map< QString , action *>::iterator dIter(mmcMap.begin()); 
    142134 
    143  
     135         
    144136        for( dIter = mmcMap.begin(); dIter != mmcMap.end(); dIter++ ) 
    145137        { 
    146                 insertNewRow( dIter->first , 0 ); 
     138                action * pAction = dIter->second; 
     139                QString actionParameter; 
     140                int actionParameterInteger = 0; 
     141 
     142                if( pAction->getParameterList().size() != 0 ){ 
     143                        actionParameter = pAction->getParameterList().at(0); 
     144                        actionParameterInteger = actionParameter.toInt(&ok,10); 
     145                } 
     146                 
     147                insertNewRow(pAction->getType() , dIter->first , 0 , actionParameterInteger ); 
    147148        } 
    148149 
    149150        for( int note = 0; note < 128; note++ ) 
    150151        { 
    151                 insertNewRow("NOTE",note); 
    152         } 
    153          
    154         insertRow( rowCount ); 
    155          
    156          
    157         QComboBox *eventBox = new QComboBox(); 
    158         connect( eventBox , SIGNAL( currentIndexChanged( int ) ) , this , SLOT( updateTable() ) ); 
    159         eventBox->insertItems( rowCount , aH->getEventList() ); 
    160         setCellWidget( rowCount, 0, eventBox ); 
    161                  
    162         QSpinBox *eventParameterSpinner = new QSpinBox(); 
    163         eventParameterSpinner->setEnabled( false ); 
    164         setCellWidget( rowCount , 1, eventParameterSpinner ); 
    165  
    166         QComboBox *actionBox = new QComboBox(); 
    167         actionBox->insertItems( rowCount, aH->getActionList() ); 
    168         setCellWidget( rowCount, 2, actionBox ); 
    169                          
    170         QSpinBox *actionParameterSpinner = new QSpinBox(); 
    171         setCellWidget( rowCount, 3, actionParameterSpinner ); 
     152                action * pAction = mM->getNoteAction( note ); 
     153                QString actionParameter; 
     154                int actionParameterInteger = 0; 
     155 
     156                if( pAction->getParameterList().size() != 0 ){ 
     157                        actionParameter = pAction->getParameterList().at(0); 
     158                        actionParameterInteger = actionParameter.toInt(&ok,10); 
     159                } 
     160 
     161                if ( pAction->getType() == "NOTHING" ) continue; 
     162 
     163                insertNewRow(pAction->getType() , "NOTE" , note , actionParameterInteger ); 
     164        } 
     165         
     166        insertNewRow("","",0,0); 
     167 
    172168} 
    173169 
     
    178174        midiMap *mM  = midiMap::getInstance(); 
    179175         
    180  
    181176        int row = 0; 
    182177         
    183         for( row = 0; row <=  rowCount; row++ ){ 
     178        for( row = 0; row <  rowCount; row++ ){ 
    184179 
    185180                QComboBox * eventCombo =  dynamic_cast <QComboBox *> ( cellWidget( row, 0 ) ); 
  • trunk/gui/src/widgets/midiTable.h

    r189 r191  
    4040                void setupMidiTable(); 
    4141                void saveMidiTable(); 
    42                 void insertNewRow(QString, int); 
     42                void insertNewRow(QString, QString, int, int); 
    4343 
    4444        private slots: