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