| 1 | /* |
|---|
| 2 | * Hydrogen |
|---|
| 3 | * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net] |
|---|
| 4 | * |
|---|
| 5 | * http://www.hydrogen-music.org |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY, without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | #include <hydrogen/action.h> |
|---|
| 24 | #include <hydrogen/midiMap.h> |
|---|
| 25 | #include <map> |
|---|
| 26 | |
|---|
| 27 | midiMap * midiMap::instance = NULL; |
|---|
| 28 | |
|---|
| 29 | midiMap::midiMap() : Object( "midiMap" ) |
|---|
| 30 | { |
|---|
| 31 | //constructor |
|---|
| 32 | for(int i = 0; i < 128; i++ ){ |
|---|
| 33 | noteArray[ i ] = new action("NOTHING"); |
|---|
| 34 | ccArray[ i ] = new action("NOTHING"); |
|---|
| 35 | } |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | midiMap::~midiMap() |
|---|
| 39 | { |
|---|
| 40 | std::map< QString , action *>::iterator dIter(mmcMap.begin()); |
|---|
| 41 | |
|---|
| 42 | for( dIter = mmcMap.begin(); dIter != mmcMap.end(); dIter++ ) |
|---|
| 43 | { |
|---|
| 44 | delete dIter->second; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | for(int i = 0; i < 128; i++){ |
|---|
| 48 | delete noteArray[ i ]; |
|---|
| 49 | delete ccArray[ i ]; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | instance = NULL; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | midiMap * midiMap::getInstance(){ |
|---|
| 56 | if( instance == NULL ){ |
|---|
| 57 | instance = new midiMap(); |
|---|
| 58 | } |
|---|
| 59 | return instance; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | map <QString,action *> midiMap::getMMCMap(){ |
|---|
| 63 | return mmcMap; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | void midiMap::registerMMCEvent( QString eventString , action * pAction ){ |
|---|
| 67 | mmcMap[ eventString ] = pAction; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | void midiMap::registerNoteEvent( int note , action * pAction ){ |
|---|
| 71 | |
|---|
| 72 | if( note >= 0 && note < 128 ){ |
|---|
| 73 | delete noteArray[ note ]; |
|---|
| 74 | noteArray[ note ] = pAction; |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | void midiMap::registerCCEvent( int parameter , action * pAction ){ |
|---|
| 80 | if( parameter >= 0 and parameter < 128 ) |
|---|
| 81 | { |
|---|
| 82 | delete ccArray[ parameter ]; |
|---|
| 83 | ccArray[ parameter ] = pAction; |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | action * midiMap::getMMCAction( QString eventString ){ |
|---|
| 88 | |
|---|
| 89 | std::map< QString , action *>::iterator dIter; |
|---|
| 90 | dIter = mmcMap.find( eventString ); |
|---|
| 91 | if ( dIter == mmcMap.end() ){ |
|---|
| 92 | return NULL; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | return mmcMap[eventString]; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | action * midiMap::getNoteAction( int note ){ |
|---|
| 99 | return noteArray[ note ]; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | action * midiMap::getCCAction( int parameter ){ |
|---|
| 103 | return ccArray[ parameter ]; |
|---|
| 104 | } |
|---|
| 105 | |
|---|