root/branches/undo/src/gui/src/SoundLibrary/SoundLibraryPanel.cpp @ 2226

Revision 2226, 24.4 KB (checked in by jeremyz, 2 years ago)

kill data_path.(cpp|h) yeah git add src/core/include/hydrogen/helpers/filesystem.h

Line 
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/DrumPatternEditor.h"
41#include "../PatternEditor/PatternEditorInstrumentList.h"
42#include "../InstrumentRack.h"
43#include "../InstrumentEditor/InstrumentEditorPanel.h"
44
45#include <hydrogen/LocalFileMng.h>
46#include <hydrogen/basics/adsr.h>
47#include <hydrogen/audio_engine.h>
48#include <hydrogen/h2_exception.h>
49#include <hydrogen/hydrogen.h>
50#include <hydrogen/basics/instrument.h>
51#include <hydrogen/basics/instrument_list.h>
52#include <hydrogen/Preferences.h>
53#include <hydrogen/basics/pattern.h>
54#include <hydrogen/basics/pattern_list.h>
55#include <hydrogen/basics/sample.h>
56#include <hydrogen/basics/song.h>
57#include <hydrogen/helpers/filesystem.h>
58
59using namespace H2Core;
60
61#include <cassert>
62
63const char* SoundLibraryPanel::__class_name = "SoundLibraryPanel";
64
65SoundLibraryPanel::SoundLibraryPanel( QWidget *pParent )
66 : QWidget( pParent )
67 , Object( __class_name )
68 , __sound_library_tree( NULL )
69 , __drumkit_menu( NULL )
70 , __instrument_menu( NULL )
71 , __song_menu( NULL )
72 , __pattern_menu( NULL )
73 , __pattern_menu_list( NULL )
74 , __system_drumkits_item( NULL )
75 , __user_drumkits_item( NULL )
76 , __song_item( NULL )
77 , __pattern_item( NULL )
78 , __pattern_item_list( NULL )
79{
80        //INFOLOG( "INIT" );
81        __drumkit_menu = new QMenu( this );
82        __drumkit_menu->addAction( trUtf8( "Load" ), this, SLOT( on_drumkitLoadAction() ) );
83        __drumkit_menu->addAction( trUtf8( "Export" ), this, SLOT( on_drumkitExportAction() ) );
84        __drumkit_menu->addAction( trUtf8( "Properties" ), this, SLOT( on_drumkitPropertiesAction() ) );
85        __drumkit_menu->addSeparator();
86        __drumkit_menu->addAction( trUtf8( "Delete" ), this, SLOT( on_drumkitDeleteAction() ) );
87
88        __instrument_menu = new QMenu( this );
89        __instrument_menu->addSeparator();
90        __instrument_menu->addAction( trUtf8( "Delete" ), this, SLOT( on_instrumentDeleteAction() ) );
91
92        __song_menu = new QMenu( this );
93        __song_menu->addSeparator();
94        __song_menu->addAction( trUtf8( "Load" ), this, SLOT( on_songLoadAction() ) );
95
96        __pattern_menu = new QMenu( this );
97        __pattern_menu->addSeparator();
98        __pattern_menu->addAction( trUtf8( "Load" ), this, SLOT( on_patternLoadAction() ) );
99        __pattern_menu->addAction( trUtf8( "Delete" ), this, SLOT( on_patternDeleteAction() ) );
100
101        __pattern_menu_list = new QMenu( this );
102        __pattern_menu_list->addSeparator();
103        __pattern_menu_list->addAction( trUtf8( "Load" ), this, SLOT( on_patternLoadAction() ) );
104
105// DRUMKIT LIST
106        __sound_library_tree = new SoundLibraryTree( NULL );
107        connect( __sound_library_tree, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem* ) ), this, SLOT( on_DrumkitList_ItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) );
108        connect( __sound_library_tree, SIGNAL( itemActivated ( QTreeWidgetItem*, int ) ), this, SLOT( on_DrumkitList_itemActivated( QTreeWidgetItem*, int ) ) );
109        connect( __sound_library_tree, SIGNAL( leftClicked(QPoint) ), this, SLOT( on_DrumkitList_leftClicked(QPoint)) );
110        connect( __sound_library_tree, SIGNAL( rightClicked(QPoint) ), this, SLOT( on_DrumkitList_rightClicked(QPoint)) );
111        connect( __sound_library_tree, SIGNAL( onMouseMove( QMouseEvent* ) ), this, SLOT( on_DrumkitList_mouseMove( QMouseEvent* ) ) );
112
113
114        // LAYOUT
115        QVBoxLayout *pVBox = new QVBoxLayout();
116        pVBox->setSpacing( 0 );
117        pVBox->setMargin( 0 );
118
119        pVBox->addWidget( __sound_library_tree );
120       
121
122        this->setLayout( pVBox );
123
124        __expand_pattern_list = Preferences::get_instance()->__expandPatternItem;
125        __expand_songs_list = Preferences::get_instance()->__expandSongItem;
126
127        updateDrumkitList();
128}
129
130
131
132SoundLibraryPanel::~SoundLibraryPanel()
133{
134        for (uint i = 0; i < __system_drumkit_info_list.size(); ++i ) {
135                delete __system_drumkit_info_list[i];
136        }
137        __system_drumkit_info_list.clear();
138
139        for (uint i = 0; i < __user_drumkit_info_list.size(); ++i ) {
140                delete __user_drumkit_info_list[i];
141        }
142        __user_drumkit_info_list.clear();
143
144}
145
146
147
148void SoundLibraryPanel::updateDrumkitList()
149{
150        QString currentSL = Hydrogen::get_instance()->getCurrentDrumkitname();
151
152        LocalFileMng mng;
153
154        __sound_library_tree->clear();
155
156
157
158        __system_drumkits_item = new QTreeWidgetItem( __sound_library_tree );
159        __system_drumkits_item->setText( 0, trUtf8( "System drumkits" ) );
160        __sound_library_tree->setItemExpanded( __system_drumkits_item, true );
161
162        __user_drumkits_item = new QTreeWidgetItem( __sound_library_tree );
163        __user_drumkits_item->setText( 0, trUtf8( "User drumkits" ) );
164        __sound_library_tree->setItemExpanded( __user_drumkits_item, true );
165
166       
167
168        for (uint i = 0; i < __system_drumkit_info_list.size(); ++i ) {
169                delete __system_drumkit_info_list[i];
170        }
171        __system_drumkit_info_list.clear();
172
173        for (uint i = 0; i < __user_drumkit_info_list.size(); ++i ) {
174                delete __user_drumkit_info_list[i];
175        }
176        __user_drumkit_info_list.clear();
177
178        //User drumkit list
179    QStringList usr_dks = Filesystem::usr_drumkits_list();
180    for (int i = 0; i < usr_dks.size(); ++i) {
181                QString absPath = Filesystem::usr_drumkits_dir() + "/" + usr_dks[i];
182                Drumkit *pInfo = Drumkit::load( absPath );
183                if (pInfo) {
184                        __user_drumkit_info_list.push_back( pInfo );
185                        QTreeWidgetItem* pDrumkitItem = new QTreeWidgetItem( __user_drumkits_item );
186                        pDrumkitItem->setText( 0, pInfo->get_name() );
187                        if ( QString(pInfo->get_name() ) == currentSL ){
188                                pDrumkitItem->setBackgroundColor( 0, QColor( 50, 50, 50) );
189                        }
190                        InstrumentList *pInstrList = pInfo->get_instruments();
191                        for ( uint nInstr = 0; nInstr < pInstrList->size(); ++nInstr ) {
192                                Instrument *pInstr = pInstrList->get( nInstr );
193                                QTreeWidgetItem* pInstrumentItem = new QTreeWidgetItem( pDrumkitItem );
194                                pInstrumentItem->setText( 0, QString( "[%1] " ).arg( nInstr + 1 ) + pInstr->get_name() );
195                                pInstrumentItem->setToolTip( 0, pInstr->get_name() );
196                        }
197                }
198        }
199
200        //System drumkit list
201    QStringList sys_dks = Filesystem::sys_drumkits_list();
202    for (int i = 0; i < sys_dks.size(); ++i) {
203                QString absPath = Filesystem::sys_drumkits_dir() + "/" + sys_dks[i];
204                Drumkit *pInfo = Drumkit::load( absPath );
205                if (pInfo) {
206                        __system_drumkit_info_list.push_back( pInfo );
207                        QTreeWidgetItem* pDrumkitItem = new QTreeWidgetItem( __system_drumkits_item );
208                        pDrumkitItem->setText( 0, pInfo->get_name() );
209                        if ( QString( pInfo->get_name() ) == currentSL ){
210                                pDrumkitItem->setBackgroundColor( 0, QColor( 50, 50, 50) );
211                        }
212                        InstrumentList *pInstrList = pInfo->get_instruments();
213                        for ( uint nInstr = 0; nInstr < pInstrList->size(); ++nInstr ) {
214                                Instrument *pInstr = pInstrList->get( nInstr );
215                                QTreeWidgetItem* pInstrumentItem = new QTreeWidgetItem( pDrumkitItem );
216                                pInstrumentItem->setText( 0, QString( "[%1] " ).arg( nInstr + 1 ) + pInstr->get_name() );
217                                pInstrumentItem->setToolTip( 0, pInstr->get_name() );
218                        }
219                }
220        }
221       
222        //Songlist
223    QStringList songs = Filesystem::songs_list();
224        if ( songs.size() > 0 ) {
225                __song_item = new QTreeWidgetItem( __sound_library_tree );
226                __song_item->setText( 0, trUtf8( "Songs" ) );
227                __song_item->setToolTip( 0, "double click to expand the list" );
228                __sound_library_tree->setItemExpanded( __song_item, __expand_songs_list );
229                for (uint i = 0; i < songs.size(); i++) {
230                        QString absPath = Filesystem::songs_dir()+"/"+songs[i];
231                        QTreeWidgetItem* pSongItem = new QTreeWidgetItem( __song_item );
232            QString song = songs[i];
233                        pSongItem->setText( 0 , song.left( song.indexOf(".")) );
234                        pSongItem->setToolTip( 0, song );
235                }
236        }
237
238
239        //Pattern list
240        std::vector<QString> patternDirList = mng.getPatternDirList();
241        if ( patternDirList.size() > 0 ) {
242               
243                __pattern_item = new QTreeWidgetItem( __sound_library_tree );
244                __pattern_item->setText( 0, trUtf8( "Patterns" ) );
245                __pattern_item->setToolTip( 0, "double click to expand the list" );
246                __sound_library_tree->setItemExpanded( __pattern_item, __expand_pattern_list );
247                       
248                //this is to push the mng.getPatternList in all patterns/drumkit dirs
249                for (uint i = 0; i < patternDirList.size(); ++i) {
250                        QString absPath =  patternDirList[i];
251                        mng.getPatternList( absPath );
252                }
253               
254                //this is the second step to push the mng.funktion
255                std::vector<QString> allPatternDirList = mng.getallPatternList();
256                std::vector<QString> patternNameList = mng.getAllPatternName();
257                std::vector<QString> allCategoryNameList = mng.getAllCategoriesFromPattern();
258
259                //now sorting via category
260                if ( allCategoryNameList.size() > 0 ){
261                        for (uint i = 0; i < allCategoryNameList.size(); ++i) {
262                                QString categoryName = allCategoryNameList[i];
263       
264                                QTreeWidgetItem* pCategoryItem = new QTreeWidgetItem( __pattern_item );
265                                pCategoryItem->setText( 0, categoryName  );
266                                for (uint i = 0; i < allPatternDirList.size(); ++i) {
267                                        QString patternCategory = mng.getCategoryFromPatternName( allPatternDirList[i]);
268
269                                        if ( patternCategory == categoryName ){
270                                                QTreeWidgetItem* pPatternItem = new QTreeWidgetItem( pCategoryItem );
271                                                pPatternItem->setText( 0, mng.getPatternNameFromPatternDir( allPatternDirList[i] ));
272                                                pPatternItem->setToolTip( 0, mng.getDrumkitNameForPattern( allPatternDirList[i] ));
273
274                                        }
275                                }
276                        }
277                }
278        }
279
280
281}
282
283
284
285void SoundLibraryPanel::on_DrumkitList_ItemChanged( QTreeWidgetItem * current, QTreeWidgetItem * previous )
286{
287        UNUSED( current );
288        UNUSED( previous );
289        test_expandedItems();
290}
291
292
293
294void SoundLibraryPanel::on_DrumkitList_itemActivated( QTreeWidgetItem * item, int column )
295{
296        UNUSED( column );
297
298//      INFOLOG( "[on_DrumkitList_itemActivated]" );
299        if ( item == __system_drumkits_item || item == __user_drumkits_item || item == __system_drumkits_item->parent() || item->parent() == __song_item || item == __song_item || item == __pattern_item || item->parent() == __pattern_item || item->parent()->parent() == __pattern_item || item == __pattern_item_list || item->parent() == __pattern_item_list || item->parent()->parent() == __pattern_item_list ) {
300                return;
301        }
302
303        if ( item->parent() == __system_drumkits_item || item->parent() == __user_drumkits_item  ) {
304                // e' stato selezionato un drumkit
305        }
306        else {
307                // e' stato selezionato uno strumento
308                QString selectedName = item->text(0);
309                if( item->text(0) == "Patterns" ) return;
310
311                QString sInstrName = selectedName.remove( 0, selectedName.indexOf( "] " ) + 2 );
312                QString sDrumkitName = item->parent()->text(0);
313                INFOLOG( QString(sDrumkitName) + ", instr:" + sInstrName );
314
315                Instrument *pInstrument = Instrument::load_instrument( sDrumkitName, sInstrName );
316                pInstrument->set_muted( false );
317
318                AudioEngine::get_instance()->get_sampler()->preview_instrument( pInstrument );
319        }
320}
321
322
323
324
325
326
327
328void SoundLibraryPanel::on_DrumkitList_rightClicked( QPoint pos )
329{
330        if( __sound_library_tree->currentItem() == NULL )
331                return;
332       
333        if (
334                ( __sound_library_tree->currentItem()->parent() == NULL ) ||
335                ( __sound_library_tree->currentItem() == __user_drumkits_item ) ||
336                ( __sound_library_tree->currentItem() == __system_drumkits_item )
337        ) {
338                return;
339        }
340
341        if ( __sound_library_tree->currentItem()->parent() == __song_item ) {
342                __song_menu->popup( pos );
343        }
344
345        if ( __sound_library_tree->currentItem()->parent()->parent() == __pattern_item && __pattern_item != NULL ) {
346                __pattern_menu->popup( pos );
347        }
348
349        if ( __sound_library_tree->currentItem()->parent() == __user_drumkits_item ) {
350                __drumkit_menu->popup( pos );
351        }
352        else if ( __sound_library_tree->currentItem()->parent()->parent() == __user_drumkits_item ) {
353                __instrument_menu->popup( pos );
354        }
355        //else if ( __sound_library_tree->currentItem()->parent()->parent()->parent() ==  __pattern_item_list ) {
356        //      __pattern_menu_list->popup( pos );
357        //}
358       
359
360        if ( __sound_library_tree->currentItem()->parent() == __system_drumkits_item ) {
361                __drumkit_menu->popup( pos );
362        }
363        else if ( __sound_library_tree->currentItem()->parent()->parent() == __system_drumkits_item ) {
364                __instrument_menu->popup( pos );
365        }
366}
367
368
369
370void SoundLibraryPanel::on_DrumkitList_leftClicked( QPoint pos )
371{
372        __start_drag_position = pos;
373}
374
375
376
377void SoundLibraryPanel::on_DrumkitList_mouseMove( QMouseEvent *event)
378{
379        if (! ( event->buttons() & Qt::LeftButton ) ) {
380                return;
381        }
382
383        if ( ( event->pos() - __start_drag_position ).manhattanLength() < QApplication::startDragDistance() ) {
384                return;
385        }
386       
387        if ( !__sound_library_tree->currentItem() ) {
388                return;
389        }
390
391        if (
392                ( __sound_library_tree->currentItem()->parent() == __system_drumkits_item ) ||
393                ( __sound_library_tree->currentItem()->parent() == __user_drumkits_item )
394        ) {
395                // drumkit selection
396                //INFOLOG( "ho selezionato un drumkit (system)" );
397                return;
398        }
399        else {
400                //INFOLOG( "ho selezionato uno strumento" );
401                // instrument selection
402                if ( __sound_library_tree->currentItem() == NULL )
403                {
404                        return;
405                }
406               
407                if ( __sound_library_tree->currentItem()->parent() == NULL )
408                {
409                        return;
410                }
411
412                if ( __sound_library_tree->currentItem()->parent() == __song_item )
413                {
414                        return;
415                }
416
417                if ( __sound_library_tree->currentItem()->parent()->text(0) == NULL )
418                {
419                        return;
420                }
421
422                if ( __sound_library_tree->currentItem()->parent() == __pattern_item ) {
423                        return;
424                }
425
426                if ( __sound_library_tree->currentItem()->parent()->parent() == __pattern_item ) {
427
428                        LocalFileMng mng;
429               
430                        QString patternName = __sound_library_tree->currentItem()->text( 0 ) + ".h2pattern";
431                        QString drumkitname = __sound_library_tree->currentItem()->toolTip ( 0 );
432                       
433                        QString sDirectory;
434               
435                        std::vector<QString> patternDirList = mng.getPatternDirList();
436               
437                                for (uint i = 0; i < patternDirList.size(); ++i) {
438                                        QString absPath =  patternDirList[i];
439                                        mng.getPatternList( absPath );
440                                }
441               
442                        std::vector<QString> allPatternDirList = mng.getallPatternList();
443               
444                        for (uint i = 0; i < allPatternDirList.size(); ++i) {
445                                QString testName = allPatternDirList[i];
446                                if( testName.contains( patternName ) && testName.contains( drumkitname )){
447               
448                                        sDirectory = allPatternDirList[i];
449                                }
450                        }
451
452                        QString dragtype = "drag pattern";
453                        QString sText = dragtype + "::" + sDirectory;
454
455                        QDrag *pDrag = new QDrag(this);
456                        QMimeData *pMimeData = new QMimeData;
457
458                        pMimeData->setText( sText );
459                        pDrag->setMimeData( pMimeData);
460                        //drag->setPixmap(iconPixmap);
461
462                        pDrag->start( Qt::CopyAction | Qt::MoveAction );
463                        return;
464                }
465
466                QString sDrumkitName = __sound_library_tree->currentItem()->parent()->text(0);
467                QString sInstrumentName = ( __sound_library_tree->currentItem()->text(0) ).remove( 0, __sound_library_tree->currentItem()->text(0).indexOf( "] " ) + 2 );
468
469                QString sText = "importInstrument:" + sDrumkitName + "::" + sInstrumentName;
470
471                QDrag *pDrag = new QDrag(this);
472                QMimeData *pMimeData = new QMimeData;
473
474                pMimeData->setText( sText );
475                pDrag->setMimeData( pMimeData);
476                //drag->setPixmap(iconPixmap);
477
478                pDrag->start( Qt::CopyAction | Qt::MoveAction );
479        }
480}
481
482
483
484void SoundLibraryPanel::on_drumkitLoadAction()
485{
486        restore_background_color();
487
488        QString sDrumkitName = __sound_library_tree->currentItem()->text(0);
489
490        Drumkit *drumkitInfo = NULL;
491
492        // find the drumkit in the list
493        for ( uint i = 0; i < __system_drumkit_info_list.size(); i++ ) {
494                Drumkit *pInfo = __system_drumkit_info_list[i];
495                if ( pInfo->get_name() == sDrumkitName ) {
496                        drumkitInfo = pInfo;
497                        break;
498                }
499        }
500        for ( uint i = 0; i < __user_drumkit_info_list.size(); i++ ) {
501                Drumkit *pInfo = __user_drumkit_info_list[i];
502                if ( pInfo->get_name() == sDrumkitName ) {
503                        drumkitInfo = pInfo;
504                        break;
505                }
506        }
507        assert( drumkitInfo );
508
509        QApplication::setOverrideCursor(Qt::WaitCursor);
510
511        Hydrogen::get_instance()->loadDrumkit( drumkitInfo );
512        Hydrogen::get_instance()->getSong()->__is_modified = true;
513        HydrogenApp::get_instance()->onDrumkitLoad( drumkitInfo->get_name() );
514        HydrogenApp::get_instance()->getPatternEditorPanel()->getDrumPatternEditor()->updateEditor();
515        HydrogenApp::get_instance()->getPatternEditorPanel()->updatePianorollEditor();
516
517        InstrumentEditorPanel::get_instance()->updateInstrumentEditor();
518
519        __sound_library_tree->currentItem()->setBackgroundColor ( 0, QColor( 50, 50, 50) );
520        QApplication::restoreOverrideCursor();
521
522}
523
524
525
526void SoundLibraryPanel::update_background_color()
527{
528        restore_background_color();
529        change_background_color();
530}
531
532
533
534void SoundLibraryPanel::restore_background_color()
535{
536        for (int i = 0; i < __system_drumkits_item->childCount() ; i++){
537                ( __system_drumkits_item->child( i ) )->setBackground( 0, QBrush() );           
538        }
539
540        for (int i = 0; i < __user_drumkits_item->childCount() ; i++){
541                ( __user_drumkits_item->child( i ) )->setBackground(0, QBrush() );
542        }
543}
544
545
546
547void SoundLibraryPanel::change_background_color()
548{
549        QString curlib =  Hydrogen::get_instance()->getCurrentDrumkitname();
550 
551        for (int i = 0; i < __system_drumkits_item->childCount() ; i++){
552                if ( ( __system_drumkits_item->child( i ) )->text( 0 ) == curlib ){
553                        ( __system_drumkits_item->child( i ) )->setBackgroundColor ( 0, QColor( 50, 50, 50)  );
554                        break;
555                }
556        }
557
558        for (int i = 0; i < __user_drumkits_item->childCount() ; i++){
559                if ( ( __user_drumkits_item->child( i ))->text( 0 ) == curlib ){
560                        ( __user_drumkits_item->child( i ) )->setBackgroundColor ( 0, QColor( 50, 50, 50)  );
561                        break;
562                }
563        }
564}
565
566
567
568void SoundLibraryPanel::on_drumkitDeleteAction()
569{
570    QTreeWidgetItem* item = __sound_library_tree->currentItem();
571
572        //if we delete the current loaded drumkit we can get truble with some empty pointers
573    // TODO this check is really unsafe
574    if ( item->text(0) == Hydrogen::get_instance()->getCurrentDrumkitname() ){
575                QMessageBox::warning( this, "Hydrogen", QString( "You try to delet the current loaded drumkit.\nThis is not possible!") );
576                return;
577        }
578
579    if( item->parent() == __system_drumkits_item ) {
580                QMessageBox::warning( this, "Hydrogen", QString( "A system drumkit can't be deleted.") );
581                return;
582        }
583
584        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 );
585        if ( res == 1 ) {
586                return;
587        }
588
589        QApplication::setOverrideCursor(Qt::WaitCursor);
590        bool success = Drumkit::remove( item->text(0) );
591        test_expandedItems();
592        updateDrumkitList();
593        QApplication::restoreOverrideCursor();
594    if( !success) QMessageBox::warning( this, "Hydrogen", QString( "Drumkit deletion failed.") );
595}
596
597
598
599void SoundLibraryPanel::on_drumkitExportAction()
600{
601        SoundLibraryExportDialog exportDialog( this );
602        exportDialog.exec();
603}
604
605
606
607void SoundLibraryPanel::on_drumkitPropertiesAction()
608{
609        QString sDrumkitName = __sound_library_tree->currentItem()->text(0);
610
611        Drumkit *drumkitInfo = NULL;
612
613        // find the drumkit in the list
614        for ( uint i = 0; i < __system_drumkit_info_list.size(); i++ ) {
615                Drumkit *pInfo = __system_drumkit_info_list[i];
616                if ( pInfo->get_name() == sDrumkitName ) {
617                        drumkitInfo = pInfo;
618                        break;
619                }
620        }
621        for ( uint i = 0; i < __user_drumkit_info_list.size(); i++ ) {
622                Drumkit*pInfo = __user_drumkit_info_list[i];
623                if ( pInfo->get_name() == sDrumkitName ) {
624                        drumkitInfo = pInfo;
625                        break;
626                }
627        }
628
629        assert( drumkitInfo );
630
631        QString sPreDrumkitName = Hydrogen::get_instance()->getCurrentDrumkitname();
632
633        Drumkit *preDrumkitInfo = NULL;
634       
635
636        // find the drumkit in the list
637        for ( uint i = 0; i < __system_drumkit_info_list.size(); i++ ) {
638                Drumkit *prInfo = __system_drumkit_info_list[i];
639                if ( prInfo->get_name() == sPreDrumkitName ) {
640                        preDrumkitInfo = prInfo;
641                        break;
642                }
643        }
644        for ( uint i = 0; i < __user_drumkit_info_list.size(); i++ ) {
645                Drumkit *prInfo = __user_drumkit_info_list[i];
646                if ( prInfo->get_name() == sPreDrumkitName ) {
647                        preDrumkitInfo = prInfo;
648                        break;
649                }
650        }
651
652        if ( preDrumkitInfo == NULL ){
653                QMessageBox::warning( this, "Hydrogen", QString( "The current loaded song missing his soundlibrary.\nPlease load a existing soundlibrary first") );
654                return;
655        }
656        assert( preDrumkitInfo );
657       
658        //open the soundlibrary save dialog
659        SoundLibraryPropertiesDialog dialog( this , drumkitInfo, preDrumkitInfo );
660        dialog.exec();
661}
662
663
664
665void SoundLibraryPanel::on_instrumentDeleteAction()
666{
667        QMessageBox::warning( this, "Hydrogen", QString( "Not implemented yet.") );
668        ERRORLOG( "[on_instrumentDeleteAction] not implemented yet" );
669}
670
671void SoundLibraryPanel::on_songLoadAction()
672{
673        QString songName = __sound_library_tree->currentItem()->text( 0 );
674        QString sDirectory = Preferences::get_instance()->getDataDirectory()  + "songs";
675
676        QString sFilename = sDirectory + "/" + songName + ".h2song";
677       
678
679        Hydrogen *engine = Hydrogen::get_instance();
680        if ( engine->getState() == STATE_PLAYING ) {
681                engine->sequencer_stop();
682        }
683
684        Song *pSong = Song::load( sFilename );
685        if ( pSong == NULL ) {
686                QMessageBox::information( this, "Hydrogen", trUtf8("Error loading song.") );
687                return;
688        }
689
690        // add the new loaded song in the "last used song" vector
691        Preferences *pPref = Preferences::get_instance();
692
693        std::vector<QString> recentFiles = pPref->getRecentFiles();
694        recentFiles.insert( recentFiles.begin(), sFilename );
695        pPref->setRecentFiles( recentFiles );
696
697        HydrogenApp* h2app = HydrogenApp::get_instance();
698
699        h2app->setSong( pSong );
700
701        //updateRecentUsedSongList();
702        engine->setSelectedPatternNumber( 0 );
703}
704
705
706
707void SoundLibraryPanel::on_patternLoadAction()
708{
709        LocalFileMng mng;
710
711        QString patternName = __sound_library_tree->currentItem()->text( 0 ) + ".h2pattern";
712        QString drumkitname = __sound_library_tree->currentItem()->toolTip ( 0 );
713        Hydrogen *engine = Hydrogen::get_instance();
714        Song *song = engine->getSong();
715        PatternList *pPatternList = song->get_pattern_list();
716       
717        QString sDirectory;
718
719        std::vector<QString> patternDirList = mng.getPatternDirList();
720
721        for (uint i = 0; i < patternDirList.size(); ++i) {
722                QString absPath =  patternDirList[i];
723                mng.getPatternList( absPath );
724        }
725
726        std::vector<QString> allPatternDirList = mng.getallPatternList();
727
728        for (uint i = 0; i < allPatternDirList.size(); ++i) {
729                QString testName = allPatternDirList[i];
730                if( testName.contains( patternName ) && testName.contains( drumkitname )){
731                        sDirectory = allPatternDirList[i];             
732                }
733        }
734
735        Pattern* err = mng.loadPattern (sDirectory );
736
737        if ( err == 0 ) {
738                ERRORLOG( "Error loading the pattern" );
739        }
740        else {
741                H2Core::Pattern *pNewPattern = err;
742                pPatternList->add ( pNewPattern );
743                song->__is_modified = true;
744        }
745
746        HydrogenApp::get_instance()->getSongEditorPanel()->updateAll();
747}
748
749
750void SoundLibraryPanel::on_patternDeleteAction()
751{
752        LocalFileMng mng;
753
754        QString patternName = __sound_library_tree->currentItem()->text( 0 ) + ".h2pattern";
755        QString drumkitname = __sound_library_tree->currentItem()->toolTip ( 0 );
756       
757        QString sDirectory = "";
758
759        std::vector<QString> patternDirList = mng.getPatternDirList();
760
761        for (uint i = 0; i < patternDirList.size(); ++i) {
762                QString absPath =  patternDirList[i];
763                mng.getPatternList( absPath );
764        }
765
766        std::vector<QString> allPatternDirList = mng.getallPatternList();
767
768        for (uint i = 0; i < allPatternDirList.size(); ++i) {
769                QString testName = allPatternDirList[i];
770                if( testName.contains( patternName ) && testName.contains( drumkitname )){
771                        sDirectory = allPatternDirList[i];             
772                }
773        }
774
775        int res = QMessageBox::information( this, "Hydrogen", tr( "Warning, the selected pattern will be deleted from disk.\nAre you sure?"), tr("&Ok"), tr("&Cancel"), 0, 1 );
776        if ( res == 1 ) {
777                return;
778        }
779
780        QFile rmfile(sDirectory );
781        bool err = rmfile.remove();
782        if ( err == false ) {
783                ERRORLOG( "Error removing the pattern" );
784        }
785
786        test_expandedItems();
787        updateDrumkitList();
788}
789
790
791void SoundLibraryPanel::test_expandedItems()
792{
793        assert( __sound_library_tree );
794        __expand_songs_list = __sound_library_tree->isItemExpanded( __song_item );
795        __expand_pattern_list = __sound_library_tree->isItemExpanded( __pattern_item );
796        Preferences::get_instance()->__expandSongItem = __expand_songs_list;
797        Preferences::get_instance()->__expandPatternItem = __expand_pattern_list;
798        //ERRORLOG( QString("songs %1 patterns %2").arg(__expand_songs_list).arg(__expand_pattern_list) );
799}
Note: See TracBrowser for help on using the browser.