| 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 "SoundLibraryPanel.h" |
|---|
| 24 | |
|---|
| 25 | #include <QtGui> |
|---|
| 26 | |
|---|
| 27 | #include "SoundLibraryTree.h" |
|---|
| 28 | #include "FileBrowser.h" |
|---|
| 29 | |
|---|
| 30 | #include "SoundLibrarySaveDialog.h" |
|---|
| 31 | #include "SoundLibraryPropertiesDialog.h" |
|---|
| 32 | #include "SoundLibraryExportDialog.h" |
|---|
| 33 | |
|---|
| 34 | #include "../HydrogenApp.h" |
|---|
| 35 | #include "../widgets/Button.h" |
|---|
| 36 | #include "../widgets/PixmapWidget.h" |
|---|
| 37 | #include "../Skin.h" |
|---|
| 38 | #include "../SongEditor/SongEditorPanel.h" |
|---|
| 39 | #include "../PatternEditor/PatternEditorPanel.h" |
|---|
| 40 | #include "../PatternEditor/PatternEditorInstrumentList.h" |
|---|
| 41 | #include "../InstrumentRack.h" |
|---|
| 42 | |
|---|
| 43 | #include <hydrogen/LocalFileMng.h> |
|---|
| 44 | #include <hydrogen/data_path.h> |
|---|
| 45 | #include <hydrogen/sample.h> |
|---|
| 46 | #include <hydrogen/adsr.h> |
|---|
| 47 | #include <hydrogen/hydrogen.h> |
|---|
| 48 | #include <hydrogen/instrument.h> |
|---|
| 49 | #include <hydrogen/h2_exception.h> |
|---|
| 50 | #include <hydrogen/audio_engine.h> |
|---|
| 51 | #include <hydrogen/Preferences.h> |
|---|
| 52 | using namespace H2Core; |
|---|
| 53 | |
|---|
| 54 | #include <cassert> |
|---|
| 55 | |
|---|
| 56 | SoundLibraryPanel::SoundLibraryPanel( QWidget *pParent ) |
|---|
| 57 | : QWidget( pParent ) |
|---|
| 58 | , Object( "SoundLibraryPanel" ) |
|---|
| 59 | { |
|---|
| 60 | //INFOLOG( "INIT" ); |
|---|
| 61 | |
|---|
| 62 | m_pDrumkitMenu = new QMenu( this ); |
|---|
| 63 | m_pDrumkitMenu->addAction( trUtf8( "Load" ), this, SLOT( on_drumkitLoadAction() ) ); |
|---|
| 64 | m_pDrumkitMenu->addAction( trUtf8( "Export" ), this, SLOT( on_drumkitExportAction() ) ); |
|---|
| 65 | m_pDrumkitMenu->addAction( trUtf8( "Properties" ), this, SLOT( on_drumkitPropertiesAction() ) ); |
|---|
| 66 | m_pDrumkitMenu->addSeparator(); |
|---|
| 67 | m_pDrumkitMenu->addAction( trUtf8( "Delete" ), this, SLOT( on_drumkitDeleteAction() ) ); |
|---|
| 68 | |
|---|
| 69 | m_pInstrumentMenu = new QMenu( this ); |
|---|
| 70 | m_pInstrumentMenu->addSeparator(); |
|---|
| 71 | m_pInstrumentMenu->addAction( trUtf8( "Delete" ), this, SLOT( on_instrumentDeleteAction() ) ); |
|---|
| 72 | |
|---|
| 73 | m_pSongMenu = new QMenu( this ); |
|---|
| 74 | m_pSongMenu->addSeparator(); |
|---|
| 75 | m_pSongMenu->addAction( trUtf8( "Load" ), this, SLOT( on_songLoadAction() ) ); |
|---|
| 76 | |
|---|
| 77 | m_pPatternMenu = new QMenu( this ); |
|---|
| 78 | m_pPatternMenu->addSeparator(); |
|---|
| 79 | m_pPatternMenu->addAction( trUtf8( "Load" ), this, SLOT( on_patternLoadAction() ) ); |
|---|
| 80 | |
|---|
| 81 | m_pPatternMenuList = new QMenu( this ); |
|---|
| 82 | m_pPatternMenuList->addSeparator(); |
|---|
| 83 | m_pPatternMenuList->addAction( trUtf8( "Load" ), this, SLOT( on_patternLoadAction() ) ); |
|---|
| 84 | |
|---|
| 85 | // DRUMKIT LIST |
|---|
| 86 | m_pSoundLibraryTree = new SoundLibraryTree( NULL ); |
|---|
| 87 | connect( m_pSoundLibraryTree, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem* ) ), this, SLOT( on_DrumkitList_ItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) ); |
|---|
| 88 | connect( m_pSoundLibraryTree, SIGNAL( itemActivated ( QTreeWidgetItem*, int ) ), this, SLOT( on_DrumkitList_itemActivated( QTreeWidgetItem*, int ) ) ); |
|---|
| 89 | connect( m_pSoundLibraryTree, SIGNAL( leftClicked(QPoint) ), this, SLOT( on_DrumkitList_leftClicked(QPoint)) ); |
|---|
| 90 | connect( m_pSoundLibraryTree, SIGNAL( rightClicked(QPoint) ), this, SLOT( on_DrumkitList_rightClicked(QPoint)) ); |
|---|
| 91 | connect( m_pSoundLibraryTree, SIGNAL( onMouseMove( QMouseEvent* ) ), this, SLOT( on_DrumkitList_mouseMove( QMouseEvent* ) ) ); |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | // LAYOUT |
|---|
| 95 | QVBoxLayout *pVBox = new QVBoxLayout(); |
|---|
| 96 | pVBox->setSpacing( 0 ); |
|---|
| 97 | pVBox->setMargin( 0 ); |
|---|
| 98 | |
|---|
| 99 | pVBox->addWidget( m_pSoundLibraryTree ); |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | this->setLayout( pVBox ); |
|---|
| 103 | |
|---|
| 104 | updateDrumkitList(); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | SoundLibraryPanel::~SoundLibraryPanel() |
|---|
| 110 | { |
|---|
| 111 | for (uint i = 0; i < m_systemDrumkitInfoList.size(); ++i ) { |
|---|
| 112 | delete m_systemDrumkitInfoList[i]; |
|---|
| 113 | } |
|---|
| 114 | m_systemDrumkitInfoList.clear(); |
|---|
| 115 | |
|---|
| 116 | for (uint i = 0; i < m_userDrumkitInfoList.size(); ++i ) { |
|---|
| 117 | delete m_userDrumkitInfoList[i]; |
|---|
| 118 | } |
|---|
| 119 | m_userDrumkitInfoList.clear(); |
|---|
| 120 | |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | void SoundLibraryPanel::updateDrumkitList() |
|---|
| 126 | { |
|---|
| 127 | LocalFileMng mng; |
|---|
| 128 | |
|---|
| 129 | m_pSoundLibraryTree->clear(); |
|---|
| 130 | |
|---|
| 131 | std::vector<QString> songList = mng.getSongList(); |
|---|
| 132 | |
|---|
| 133 | if ( songList.size() > 0 ) |
|---|
| 134 | { |
|---|
| 135 | |
|---|
| 136 | m_pSongItem = new QTreeWidgetItem( m_pSoundLibraryTree ); |
|---|
| 137 | m_pSongItem->setText( 0, trUtf8( "Songs" ) ); |
|---|
| 138 | m_pSongItem->setToolTip( 0, "double click to expand the list" ); |
|---|
| 139 | |
|---|
| 140 | for (uint i = 0; i < songList.size(); i++) |
|---|
| 141 | { |
|---|
| 142 | QString absPath = DataPath::get_data_path() + "/songs/" + songList[i]; |
|---|
| 143 | QTreeWidgetItem* pSongItem = new QTreeWidgetItem( m_pSongItem ); |
|---|
| 144 | pSongItem->setText( 0 , songList[ i ] ); |
|---|
| 145 | pSongItem->setToolTip( 0, songList[ i ] ); |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | //std::vector<QString> patternListforDrumkit = mng.getPatternsForDrumkit( pInfo->getName() ); |
|---|
| 152 | std::vector<QString> patternDirList = mng.getPatternDirList(); |
|---|
| 153 | if ( patternDirList.size() > 0 ) |
|---|
| 154 | { |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | m_pPatternItem = new QTreeWidgetItem( m_pSoundLibraryTree ); |
|---|
| 158 | m_pPatternItem->setText( 0, trUtf8( "Patterns" ) ); |
|---|
| 159 | m_pPatternItem->setToolTip( 0, "double click to expand the list" ); |
|---|
| 160 | |
|---|
| 161 | //this is to push the mng.getPatternList in all patterns/drumkit dirs |
|---|
| 162 | for (uint i = 0; i < patternDirList.size(); ++i) { |
|---|
| 163 | QString absPath = patternDirList[i]; |
|---|
| 164 | mng.getPatternList( absPath ); |
|---|
| 165 | } |
|---|
| 166 | //this is the second step to push the mng.funktion |
|---|
| 167 | std::vector<QString> allPatternDirList = mng.getallPatternList(); |
|---|
| 168 | std::vector<QString> patternNameList = mng.getAllPatternName(); |
|---|
| 169 | std::vector<QString> allCategoryNameList = mng.getAllCategoriesFromPattern(); |
|---|
| 170 | |
|---|
| 171 | //now sorting via category |
|---|
| 172 | if ( allCategoryNameList.size() > 0 ){ |
|---|
| 173 | for (uint i = 0; i < allCategoryNameList.size(); ++i) { |
|---|
| 174 | QString categoryName = allCategoryNameList[i]; |
|---|
| 175 | |
|---|
| 176 | QTreeWidgetItem* pCategoryItem = new QTreeWidgetItem( m_pPatternItem ); |
|---|
| 177 | pCategoryItem->setText( 0, categoryName ); |
|---|
| 178 | for (uint i = 0; i < allPatternDirList.size(); ++i) { |
|---|
| 179 | QString patternCategory = mng.getCategoryFromPatternName( allPatternDirList[i]); |
|---|
| 180 | |
|---|
| 181 | if ( patternCategory == categoryName ){ |
|---|
| 182 | QTreeWidgetItem* pPatternItem = new QTreeWidgetItem( pCategoryItem ); |
|---|
| 183 | pPatternItem->setText( 0, mng.getPatternNameFromPatternDir( allPatternDirList[i] )); |
|---|
| 184 | pPatternItem->setToolTip( 0, mng.getDrumkitNameForPattern( allPatternDirList[i] )); |
|---|
| 185 | |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | m_pSystemDrumkitsItem = new QTreeWidgetItem( m_pSoundLibraryTree ); |
|---|
| 197 | m_pSystemDrumkitsItem->setText( 0, trUtf8( "System drumkits" ) ); |
|---|
| 198 | m_pSoundLibraryTree->setItemExpanded( m_pSystemDrumkitsItem, true ); |
|---|
| 199 | |
|---|
| 200 | m_pUserDrumkitsItem = new QTreeWidgetItem( m_pSoundLibraryTree ); |
|---|
| 201 | m_pUserDrumkitsItem->setText( 0, trUtf8( "User drumkits" ) ); |
|---|
| 202 | m_pSoundLibraryTree->setItemExpanded( m_pUserDrumkitsItem, true ); |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | for (uint i = 0; i < m_systemDrumkitInfoList.size(); ++i ) { |
|---|
| 207 | delete m_systemDrumkitInfoList[i]; |
|---|
| 208 | } |
|---|
| 209 | m_systemDrumkitInfoList.clear(); |
|---|
| 210 | |
|---|
| 211 | for (uint i = 0; i < m_userDrumkitInfoList.size(); ++i ) { |
|---|
| 212 | delete m_userDrumkitInfoList[i]; |
|---|
| 213 | } |
|---|
| 214 | m_userDrumkitInfoList.clear(); |
|---|
| 215 | |
|---|
| 216 | std::vector<QString> userList = Drumkit::getUserDrumkitList(); |
|---|
| 217 | for (uint i = 0; i < userList.size(); ++i) { |
|---|
| 218 | QString absPath = userList[i]; |
|---|
| 219 | Drumkit *pInfo = mng.loadDrumkit( absPath ); |
|---|
| 220 | |
|---|
| 221 | QString filenameforpattern = absPath + "/patterns/"; |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | if (pInfo) { |
|---|
| 225 | |
|---|
| 226 | m_userDrumkitInfoList.push_back( pInfo ); |
|---|
| 227 | |
|---|
| 228 | QTreeWidgetItem* pDrumkitItem = new QTreeWidgetItem( m_pUserDrumkitsItem ); |
|---|
| 229 | pDrumkitItem->setText( 0, pInfo->getName() ); |
|---|
| 230 | |
|---|
| 231 | InstrumentList *pInstrList = pInfo->getInstrumentList(); |
|---|
| 232 | for ( uint nInstr = 0; nInstr < pInstrList->get_size(); ++nInstr ) { |
|---|
| 233 | Instrument *pInstr = pInstrList->get( nInstr ); |
|---|
| 234 | |
|---|
| 235 | QTreeWidgetItem* pInstrumentItem = new QTreeWidgetItem( pDrumkitItem ); |
|---|
| 236 | pInstrumentItem->setText( 0, QString( "[%1] " ).arg( nInstr + 1 ) + pInstr->get_name() ); |
|---|
| 237 | pInstrumentItem->setToolTip( 0, pInstr->get_name() ); |
|---|
| 238 | } |
|---|
| 239 | } |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | std::vector<QString> systemList = Drumkit::getSystemDrumkitList(); |
|---|
| 243 | |
|---|
| 244 | for (uint i = 0; i < systemList.size(); i++) { |
|---|
| 245 | QString absPath = systemList[i]; |
|---|
| 246 | Drumkit *pInfo = mng.loadDrumkit( absPath ); |
|---|
| 247 | if (pInfo) { |
|---|
| 248 | m_systemDrumkitInfoList.push_back( pInfo ); |
|---|
| 249 | |
|---|
| 250 | QTreeWidgetItem* pDrumkitItem = new QTreeWidgetItem( m_pSystemDrumkitsItem ); |
|---|
| 251 | pDrumkitItem->setText( 0, pInfo->getName() ); |
|---|
| 252 | |
|---|
| 253 | InstrumentList *pInstrList = pInfo->getInstrumentList(); |
|---|
| 254 | for ( uint nInstr = 0; nInstr < pInstrList->get_size(); ++nInstr ) { |
|---|
| 255 | Instrument *pInstr = pInstrList->get( nInstr ); |
|---|
| 256 | |
|---|
| 257 | QTreeWidgetItem* pInstrumentItem = new QTreeWidgetItem( pDrumkitItem ); |
|---|
| 258 | pInstrumentItem->setText( 0, QString( "[%1] " ).arg( nInstr + 1 ) + pInstr->get_name() ); |
|---|
| 259 | pInstrumentItem->setToolTip( 0, pInstr->get_name() ); |
|---|
| 260 | } |
|---|
| 261 | } |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | void SoundLibraryPanel::on_DrumkitList_ItemChanged( QTreeWidgetItem * current, QTreeWidgetItem * previous ) |
|---|
| 268 | { |
|---|
| 269 | UNUSED( current ); |
|---|
| 270 | UNUSED( previous ); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | void SoundLibraryPanel::on_DrumkitList_itemActivated( QTreeWidgetItem * item, int column ) |
|---|
| 276 | { |
|---|
| 277 | UNUSED( column ); |
|---|
| 278 | |
|---|
| 279 | // INFOLOG( "[on_DrumkitList_itemActivated]" ); |
|---|
| 280 | if ( item == m_pSystemDrumkitsItem || item == m_pUserDrumkitsItem || item == m_pSystemDrumkitsItem->parent() || item->parent() == m_pSongItem || item == m_pSongItem || item == m_pPatternItem || item->parent() == m_pPatternItem || item->parent()->parent() == m_pPatternItem || item == m_pPatternItemList || item->parent() == m_pPatternItemList || item->parent()->parent() == m_pPatternItemList ) { |
|---|
| 281 | return; |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | if ( item->parent() == m_pSystemDrumkitsItem || item->parent() == m_pUserDrumkitsItem ) { |
|---|
| 285 | // e' stato selezionato un drumkit |
|---|
| 286 | } |
|---|
| 287 | else { |
|---|
| 288 | // e' stato selezionato uno strumento |
|---|
| 289 | QString selectedName = item->text(0); |
|---|
| 290 | if( item->text(0) == "Patterns" ) return; |
|---|
| 291 | |
|---|
| 292 | QString sInstrName = selectedName.remove( 0, selectedName.indexOf( "] " ) + 2 ); |
|---|
| 293 | QString sDrumkitName = item->parent()->text(0); |
|---|
| 294 | INFOLOG( QString(sDrumkitName) + ", instr:" + sInstrName ); |
|---|
| 295 | |
|---|
| 296 | Instrument *pInstrument = Instrument::load_instrument( sDrumkitName, sInstrName ); |
|---|
| 297 | pInstrument->set_muted( false ); |
|---|
| 298 | |
|---|
| 299 | AudioEngine::get_instance()->get_sampler()->preview_instrument( pInstrument ); |
|---|
| 300 | } |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | void SoundLibraryPanel::on_DrumkitList_rightClicked( QPoint pos ) |
|---|
| 310 | { |
|---|
| 311 | if( m_pSoundLibraryTree->currentItem() == NULL ) |
|---|
| 312 | return; |
|---|
| 313 | |
|---|
| 314 | if ( |
|---|
| 315 | ( m_pSoundLibraryTree->currentItem()->parent() == NULL ) || |
|---|
| 316 | ( m_pSoundLibraryTree->currentItem() == m_pUserDrumkitsItem ) || |
|---|
| 317 | ( m_pSoundLibraryTree->currentItem() == m_pSystemDrumkitsItem ) |
|---|
| 318 | ) { |
|---|
| 319 | return; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | if ( m_pSoundLibraryTree->currentItem()->parent() == m_pSongItem ) { |
|---|
| 323 | m_pSongMenu->popup( pos ); |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | if ( m_pSoundLibraryTree->currentItem()->parent()->parent() == m_pPatternItem ) { |
|---|
| 327 | m_pPatternMenu->popup( pos ); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | if ( m_pSoundLibraryTree->currentItem()->parent() == m_pUserDrumkitsItem ) { |
|---|
| 331 | m_pDrumkitMenu->popup( pos ); |
|---|
| 332 | } |
|---|
| 333 | else if ( m_pSoundLibraryTree->currentItem()->parent()->parent() == m_pUserDrumkitsItem ) { |
|---|
| 334 | m_pInstrumentMenu->popup( pos ); |
|---|
| 335 | } |
|---|
| 336 | //else if ( m_pSoundLibraryTree->currentItem()->parent()->parent()->parent() == m_pPatternItemList ) { |
|---|
| 337 | // m_pPatternMenuList->popup( pos ); |
|---|
| 338 | //} |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | if ( m_pSoundLibraryTree->currentItem()->parent() == m_pSystemDrumkitsItem ) { |
|---|
| 342 | m_pDrumkitMenu->popup( pos ); |
|---|
| 343 | } |
|---|
| 344 | else if ( m_pSoundLibraryTree->currentItem()->parent()->parent() == m_pSystemDrumkitsItem ) { |
|---|
| 345 | m_pInstrumentMenu->popup( pos ); |
|---|
| 346 | } |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | void SoundLibraryPanel::on_DrumkitList_leftClicked( QPoint pos ) |
|---|
| 352 | { |
|---|
| 353 | m_startDragPosition = pos; |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | |
|---|
| 357 | |
|---|
| 358 | void SoundLibraryPanel::on_DrumkitList_mouseMove( QMouseEvent *event) |
|---|
| 359 | { |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | if (! ( event->buttons() & Qt::LeftButton ) ) { |
|---|
| 363 | return; |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | if ( ( event->pos() - m_startDragPosition ).manhattanLength() < QApplication::startDragDistance() ) { |
|---|
| 368 | return; |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | if ( !m_pSoundLibraryTree->currentItem() ) { |
|---|
| 372 | return; |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | if ( |
|---|
| 376 | ( m_pSoundLibraryTree->currentItem()->parent() == m_pSystemDrumkitsItem ) || |
|---|
| 377 | ( m_pSoundLibraryTree->currentItem()->parent() == m_pUserDrumkitsItem ) |
|---|
| 378 | ) { |
|---|
| 379 | // drumkit selection |
|---|
| 380 | //INFOLOG( "ho selezionato un drumkit (system)" ); |
|---|
| 381 | return; |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | else { |
|---|
| 385 | //INFOLOG( "ho selezionato uno strumento" ); |
|---|
| 386 | // instrument selection |
|---|
| 387 | if ( m_pSoundLibraryTree->currentItem() == NULL ) |
|---|
| 388 | { |
|---|
| 389 | return; |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | if ( m_pSoundLibraryTree->currentItem()->parent() == NULL ) |
|---|
| 393 | { |
|---|
| 394 | return; |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| 397 | if ( m_pSoundLibraryTree->currentItem()->parent()->text(0) == NULL ) |
|---|
| 398 | { |
|---|
| 399 | return; |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | QString sDrumkitName = m_pSoundLibraryTree->currentItem()->parent()->text(0); |
|---|
| 404 | QString sInstrumentName = ( m_pSoundLibraryTree->currentItem()->text(0) ).remove( 0, m_pSoundLibraryTree->currentItem()->text(0).indexOf( "] " ) + 2 ); |
|---|
| 405 | |
|---|
| 406 | QString sText = sDrumkitName + "::" + sInstrumentName; |
|---|
| 407 | |
|---|
| 408 | QDrag *pDrag = new QDrag(this); |
|---|
| 409 | QMimeData *pMimeData = new QMimeData; |
|---|
| 410 | |
|---|
| 411 | pMimeData->setText( sText ); |
|---|
| 412 | pDrag->setMimeData( pMimeData); |
|---|
| 413 | //drag->setPixmap(iconPixmap); |
|---|
| 414 | |
|---|
| 415 | pDrag->start( Qt::CopyAction | Qt::MoveAction ); |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | void SoundLibraryPanel::on_drumkitLoadAction() |
|---|
| 423 | { |
|---|
| 424 | QString sDrumkitName = m_pSoundLibraryTree->currentItem()->text(0); |
|---|
| 425 | |
|---|
| 426 | Drumkit *drumkitInfo = NULL; |
|---|
| 427 | |
|---|
| 428 | // find the drumkit in the list |
|---|
| 429 | for ( uint i = 0; i < m_systemDrumkitInfoList.size(); i++ ) { |
|---|
| 430 | Drumkit *pInfo = m_systemDrumkitInfoList[i]; |
|---|
| 431 | if ( pInfo->getName() == sDrumkitName ) { |
|---|
| 432 | drumkitInfo = pInfo; |
|---|
| 433 | break; |
|---|
| 434 | } |
|---|
| 435 | } |
|---|
| 436 | for ( uint i = 0; i < m_userDrumkitInfoList.size(); i++ ) { |
|---|
| 437 | Drumkit*pInfo = m_userDrumkitInfoList[i]; |
|---|
| 438 | if ( pInfo->getName() == sDrumkitName ) { |
|---|
| 439 | drumkitInfo = pInfo; |
|---|
| 440 | break; |
|---|
| 441 | } |
|---|
| 442 | } |
|---|
| 443 | assert( drumkitInfo ); |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | setCursor( QCursor( Qt::WaitCursor ) ); |
|---|
| 447 | |
|---|
| 448 | Hydrogen::get_instance()->loadDrumkit( drumkitInfo ); |
|---|
| 449 | Hydrogen::get_instance()->getSong()->__is_modified = true; |
|---|
| 450 | HydrogenApp::getInstance()->setStatusBarMessage( trUtf8( "Drumkit loaded: [%1]" ).arg( drumkitInfo->getName() ), 2000 ); |
|---|
| 451 | |
|---|
| 452 | setCursor( QCursor( Qt::ArrowCursor ) ); |
|---|
| 453 | |
|---|
| 454 | // update drumkit info in save tab |
|---|
| 455 | //saveTab_nameTxt ->setText( QString( drumkitInfo->getName().c_str() ) ); |
|---|
| 456 | //saveTab_authorTxt->setText( QString( drumkitInfo->getAuthor().c_str() ) ); |
|---|
| 457 | //saveTab_infoTxt->append( QString( drumkitInfo->getInfo().c_str() ) ); |
|---|
| 458 | |
|---|
| 459 | // HydrogenApp::getInstance()->getPatternEditorPanel()->getPatternEditor()->updateEditor( true ); |
|---|
| 460 | |
|---|
| 461 | //HydrogenApp::getInstance()->getPatternEditorPanel()->getDrumPatternEditor()->updateEditor(); |
|---|
| 462 | } |
|---|
| 463 | |
|---|
| 464 | |
|---|
| 465 | |
|---|
| 466 | void SoundLibraryPanel::on_drumkitDeleteAction() |
|---|
| 467 | { |
|---|
| 468 | QString sSoundLibrary = m_pSoundLibraryTree->currentItem()->text( 0 ); |
|---|
| 469 | |
|---|
| 470 | //if we delete the current loaded drumkit we can get truble with some empty pointers |
|---|
| 471 | if ( sSoundLibrary == Hydrogen::get_instance()->getCurrentDrumkitname() ){ |
|---|
| 472 | QMessageBox::warning( this, "Hydrogen", QString( "You try to delet the current loaded drumkit.\nThis is not possible!") ); |
|---|
| 473 | return; |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | bool bIsUserSoundLibrary = false; |
|---|
| 477 | std::vector<QString> userList = Drumkit::getUserDrumkitList(); |
|---|
| 478 | for ( uint i = 0; i < userList.size(); ++i ) { |
|---|
| 479 | if ( userList[ i ].endsWith( sSoundLibrary ) ) { |
|---|
| 480 | bIsUserSoundLibrary = true; |
|---|
| 481 | break; |
|---|
| 482 | } |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | if ( bIsUserSoundLibrary == false ) { |
|---|
| 486 | QMessageBox::warning( this, "Hydrogen", QString( "A system drumkit can't be deleted.") ); |
|---|
| 487 | return; |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | int res = QMessageBox::information( this, "Hydrogen", tr( "Warning, the selected drumkit will be deleted from disk.\nAre you sure?"), tr("&Ok"), tr("&Cancel"), 0, 1 ); |
|---|
| 491 | if ( res == 1 ) { |
|---|
| 492 | return; |
|---|
| 493 | } |
|---|
| 494 | |
|---|
| 495 | Drumkit::removeDrumkit( sSoundLibrary ); |
|---|
| 496 | |
|---|
| 497 | HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList(); |
|---|
| 498 | } |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | void SoundLibraryPanel::on_drumkitExportAction() |
|---|
| 503 | { |
|---|
| 504 | SoundLibraryExportDialog exportDialog( this ); |
|---|
| 505 | exportDialog.exec(); |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | void SoundLibraryPanel::on_drumkitPropertiesAction() |
|---|
| 511 | { |
|---|
| 512 | |
|---|
| 513 | QString sDrumkitName = m_pSoundLibraryTree->currentItem()->text(0); |
|---|
| 514 | |
|---|
| 515 | Drumkit *drumkitInfo = NULL; |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | // find the drumkit in the list |
|---|
| 519 | for ( uint i = 0; i < m_systemDrumkitInfoList.size(); i++ ) { |
|---|
| 520 | Drumkit *pInfo = m_systemDrumkitInfoList[i]; |
|---|
| 521 | if ( pInfo->getName() == sDrumkitName ) { |
|---|
| 522 | drumkitInfo = pInfo; |
|---|
| 523 | break; |
|---|
| 524 | } |
|---|
| 525 | } |
|---|
| 526 | for ( uint i = 0; i < m_userDrumkitInfoList.size(); i++ ) { |
|---|
| 527 | Drumkit*pInfo = m_userDrumkitInfoList[i]; |
|---|
| 528 | if ( pInfo->getName() == sDrumkitName ) { |
|---|
| 529 | drumkitInfo = pInfo; |
|---|
| 530 | break; |
|---|
| 531 | } |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | assert( drumkitInfo ); |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | QString sPreDrumkitName = Hydrogen::get_instance()->getCurrentDrumkitname(); |
|---|
| 538 | |
|---|
| 539 | Drumkit *preDrumkitInfo = NULL; |
|---|
| 540 | |
|---|
| 541 | |
|---|
| 542 | // find the drumkit in the list |
|---|
| 543 | for ( uint i = 0; i < m_systemDrumkitInfoList.size(); i++ ) { |
|---|
| 544 | Drumkit *prInfo = m_systemDrumkitInfoList[i]; |
|---|
| 545 | if ( prInfo->getName() == sPreDrumkitName ) { |
|---|
| 546 | preDrumkitInfo = prInfo; |
|---|
| 547 | break; |
|---|
| 548 | } |
|---|
| 549 | } |
|---|
| 550 | for ( uint i = 0; i < m_userDrumkitInfoList.size(); i++ ) { |
|---|
| 551 | Drumkit *prInfo = m_userDrumkitInfoList[i]; |
|---|
| 552 | if ( prInfo->getName() == sPreDrumkitName ) { |
|---|
| 553 | preDrumkitInfo = prInfo; |
|---|
| 554 | break; |
|---|
| 555 | } |
|---|
| 556 | } |
|---|
| 557 | |
|---|
| 558 | assert( preDrumkitInfo ); |
|---|
| 559 | |
|---|
| 560 | //open the soundlibrary save dialog |
|---|
| 561 | SoundLibraryPropertiesDialog dialog( this , drumkitInfo, preDrumkitInfo ); |
|---|
| 562 | dialog.exec(); |
|---|
| 563 | |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 | void SoundLibraryPanel::on_instrumentDeleteAction() |
|---|
| 569 | { |
|---|
| 570 | QMessageBox::warning( this, "Hydrogen", QString( "Not implemented yet.") ); |
|---|
| 571 | ERRORLOG( "[on_instrumentDeleteAction] not implemented yet" ); |
|---|
| 572 | } |
|---|
| 573 | |
|---|
| 574 | void SoundLibraryPanel::on_songLoadAction() |
|---|
| 575 | { |
|---|
| 576 | QString songName = m_pSoundLibraryTree->currentItem()->text( 0 ); |
|---|
| 577 | QString sDirectory = Preferences::getInstance()->getDataDirectory() + "songs"; |
|---|
| 578 | |
|---|
| 579 | QString sFilename = sDirectory + "/" + songName + ".h2song"; |
|---|
| 580 | |
|---|
| 581 | |
|---|
| 582 | Hydrogen *engine = Hydrogen::get_instance(); |
|---|
| 583 | if ( engine->getState() == STATE_PLAYING ) { |
|---|
| 584 | engine->sequencer_stop(); |
|---|
| 585 | } |
|---|
| 586 | |
|---|
| 587 | H2Core::LocalFileMng mng; |
|---|
| 588 | Song *pSong = Song::load( sFilename ); |
|---|
| 589 | if ( pSong == NULL ) { |
|---|
| 590 | QMessageBox::information( this, "Hydrogen", trUtf8("Error loading song.") ); |
|---|
| 591 | return; |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | // add the new loaded song in the "last used song" vector |
|---|
| 595 | Preferences *pPref = Preferences::getInstance(); |
|---|
| 596 | |
|---|
| 597 | std::vector<QString> recentFiles = pPref->getRecentFiles(); |
|---|
| 598 | recentFiles.insert( recentFiles.begin(), sFilename ); |
|---|
| 599 | pPref->setRecentFiles( recentFiles ); |
|---|
| 600 | |
|---|
| 601 | HydrogenApp* h2app = HydrogenApp::getInstance(); |
|---|
| 602 | |
|---|
| 603 | h2app->setSong( pSong ); |
|---|
| 604 | |
|---|
| 605 | //updateRecentUsedSongList(); |
|---|
| 606 | engine->setSelectedPatternNumber( 0 ); |
|---|
| 607 | } |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | |
|---|
| 611 | void SoundLibraryPanel::on_patternLoadAction() |
|---|
| 612 | { |
|---|
| 613 | LocalFileMng mng; |
|---|
| 614 | |
|---|
| 615 | QString patternName = m_pSoundLibraryTree->currentItem()->text( 0 ); |
|---|
| 616 | Hydrogen *engine = Hydrogen::get_instance(); |
|---|
| 617 | Song *song = engine->getSong(); |
|---|
| 618 | PatternList *pPatternList = song->get_pattern_list(); |
|---|
| 619 | |
|---|
| 620 | QString sDirectory = ""; |
|---|
| 621 | |
|---|
| 622 | std::vector<QString> patternDirList = mng.getPatternDirList(); |
|---|
| 623 | |
|---|
| 624 | for (uint i = 0; i < patternDirList.size(); ++i) { |
|---|
| 625 | QString absPath = patternDirList[i]; |
|---|
| 626 | mng.getPatternList( absPath ); |
|---|
| 627 | } |
|---|
| 628 | |
|---|
| 629 | std::vector<QString> allPatternDirList = mng.getallPatternList(); |
|---|
| 630 | |
|---|
| 631 | for (uint i = 0; i < allPatternDirList.size(); ++i) { |
|---|
| 632 | QString testName = allPatternDirList[i]; |
|---|
| 633 | if( testName.contains( patternName )){ |
|---|
| 634 | |
|---|
| 635 | sDirectory = allPatternDirList[i]; |
|---|
| 636 | |
|---|
| 637 | } |
|---|
| 638 | } |
|---|
| 639 | |
|---|
| 640 | Pattern* err = mng.loadPattern (sDirectory ); |
|---|
| 641 | |
|---|
| 642 | if ( err == 0 ) |
|---|
| 643 | { |
|---|
| 644 | _ERRORLOG ( "Error loading the pattern" ); |
|---|
| 645 | } |
|---|
| 646 | else |
|---|
| 647 | { |
|---|
| 648 | H2Core::Pattern *pNewPattern = err; |
|---|
| 649 | pPatternList->add ( pNewPattern ); |
|---|
| 650 | song->__is_modified = true; |
|---|
| 651 | } |
|---|
| 652 | |
|---|
| 653 | HydrogenApp::getInstance()->getSongEditorPanel()->updateAll(); |
|---|
| 654 | } |
|---|
| 655 | |
|---|