root/trunk/gui/src/SoundLibrary/SoundLibraryPanel.cpp @ 363

Revision 363, 19.0 KB (checked in by wolke, 5 years ago)

fix load pattern from soundlibrary panal

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/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>
52using namespace H2Core;
53
54#include <cassert>
55
56SoundLibraryPanel::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
109SoundLibraryPanel::~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
125void 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();//full pattern path list
168                std::vector<QString> patternNameList = mng.getAllPatternName();//pattern name list
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 dir = allPatternDirList[i];
180                                        //ERRORLOG( "HHHHHHHHHHHHHHHHHHHHHHHHHHHH " + dir );
181                                        QString patternCategory = mng.getCategoryFromPatternName( allPatternDirList[i]);
182
183                                        if ( patternCategory == categoryName ){
184                                                QTreeWidgetItem* pPatternItem = new QTreeWidgetItem( pCategoryItem );
185                                                pPatternItem->setText( 0, mng.getPatternNameFromPatternDir( allPatternDirList[i] ));
186                                                pPatternItem->setToolTip( 0, mng.getDrumkitNameForPattern( allPatternDirList[i] ));
187
188                                        }
189                                       
190                                }
191                        }
192                }
193
194        }
195
196
197
198        m_pSystemDrumkitsItem = new QTreeWidgetItem( m_pSoundLibraryTree );
199        m_pSystemDrumkitsItem->setText( 0, trUtf8( "System drumkits" ) );
200        m_pSoundLibraryTree->setItemExpanded( m_pSystemDrumkitsItem, true );
201
202        m_pUserDrumkitsItem = new QTreeWidgetItem( m_pSoundLibraryTree );
203        m_pUserDrumkitsItem->setText( 0, trUtf8( "User drumkits" ) );
204        m_pSoundLibraryTree->setItemExpanded( m_pUserDrumkitsItem, true );
205
206       
207
208        for (uint i = 0; i < m_systemDrumkitInfoList.size(); ++i ) {
209                delete m_systemDrumkitInfoList[i];
210        }
211        m_systemDrumkitInfoList.clear();
212
213        for (uint i = 0; i < m_userDrumkitInfoList.size(); ++i ) {
214                delete m_userDrumkitInfoList[i];
215        }
216        m_userDrumkitInfoList.clear();
217
218        std::vector<QString> userList = Drumkit::getUserDrumkitList();
219        for (uint i = 0; i < userList.size(); ++i) {
220                QString absPath =  userList[i];
221                Drumkit *pInfo = mng.loadDrumkit( absPath );
222
223                QString filenameforpattern = absPath + "/patterns/";
224               
225
226                if (pInfo) {
227
228                        m_userDrumkitInfoList.push_back( pInfo );
229
230                        QTreeWidgetItem* pDrumkitItem = new QTreeWidgetItem( m_pUserDrumkitsItem );
231                        pDrumkitItem->setText( 0, pInfo->getName() );
232
233                        InstrumentList *pInstrList = pInfo->getInstrumentList();
234                        for ( uint nInstr = 0; nInstr < pInstrList->get_size(); ++nInstr ) {
235                                Instrument *pInstr = pInstrList->get( nInstr );
236
237                                QTreeWidgetItem* pInstrumentItem = new QTreeWidgetItem( pDrumkitItem );
238                                pInstrumentItem->setText( 0, QString( "[%1] " ).arg( nInstr + 1 ) + pInstr->get_name() );
239                                pInstrumentItem->setToolTip( 0, pInstr->get_name() );
240                        }
241                }
242        }
243
244        std::vector<QString> systemList = Drumkit::getSystemDrumkitList();
245
246        for (uint i = 0; i < systemList.size(); i++) {
247                QString absPath = systemList[i];
248                Drumkit *pInfo = mng.loadDrumkit( absPath );
249                if (pInfo) {
250                        m_systemDrumkitInfoList.push_back( pInfo );
251
252                        QTreeWidgetItem* pDrumkitItem = new QTreeWidgetItem( m_pSystemDrumkitsItem );
253                        pDrumkitItem->setText( 0, pInfo->getName() );
254
255                        InstrumentList *pInstrList = pInfo->getInstrumentList();
256                        for ( uint nInstr = 0; nInstr < pInstrList->get_size(); ++nInstr ) {
257                                Instrument *pInstr = pInstrList->get( nInstr );
258
259                                QTreeWidgetItem* pInstrumentItem = new QTreeWidgetItem( pDrumkitItem );
260                                pInstrumentItem->setText( 0, QString( "[%1] " ).arg( nInstr + 1 ) + pInstr->get_name() );
261                                pInstrumentItem->setToolTip( 0, pInstr->get_name() );
262                        }
263                }
264        }
265}
266
267
268
269void SoundLibraryPanel::on_DrumkitList_ItemChanged( QTreeWidgetItem * current, QTreeWidgetItem * previous )
270{
271        UNUSED( current );
272        UNUSED( previous );
273}
274
275
276
277void SoundLibraryPanel::on_DrumkitList_itemActivated( QTreeWidgetItem * item, int column )
278{
279        UNUSED( column );
280
281//      INFOLOG( "[on_DrumkitList_itemActivated]" );
282        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 ) {
283                return;
284        }
285
286        if ( item->parent() == m_pSystemDrumkitsItem || item->parent() == m_pUserDrumkitsItem  ) {
287                // e' stato selezionato un drumkit
288        }
289        else {
290                // e' stato selezionato uno strumento
291                QString selectedName = item->text(0);
292                if( item->text(0) == "Patterns" ) return;
293
294                QString sInstrName = selectedName.remove( 0, selectedName.indexOf( "] " ) + 2 );
295                QString sDrumkitName = item->parent()->text(0);
296                INFOLOG( QString(sDrumkitName) + ", instr:" + sInstrName );
297
298                Instrument *pInstrument = Instrument::load_instrument( sDrumkitName, sInstrName );
299                pInstrument->set_muted( false );
300
301                AudioEngine::get_instance()->get_sampler()->preview_instrument( pInstrument );
302        }
303}
304
305
306
307
308
309
310
311void SoundLibraryPanel::on_DrumkitList_rightClicked( QPoint pos )
312{
313        if( m_pSoundLibraryTree->currentItem() == NULL )
314                return;
315       
316        if (
317                ( m_pSoundLibraryTree->currentItem()->parent() == NULL ) ||
318                ( m_pSoundLibraryTree->currentItem() == m_pUserDrumkitsItem ) ||
319                ( m_pSoundLibraryTree->currentItem() == m_pSystemDrumkitsItem )
320        ) {
321                return;
322        }
323
324        if ( m_pSoundLibraryTree->currentItem()->parent() == m_pSongItem ) {
325                m_pSongMenu->popup( pos );
326        }
327
328        if ( m_pSoundLibraryTree->currentItem()->parent()->parent() == m_pPatternItem ) {
329                m_pPatternMenu->popup( pos );
330        }
331
332        if ( m_pSoundLibraryTree->currentItem()->parent() == m_pUserDrumkitsItem ) {
333                m_pDrumkitMenu->popup( pos );
334        }
335        else if ( m_pSoundLibraryTree->currentItem()->parent()->parent() == m_pUserDrumkitsItem ) {
336                m_pInstrumentMenu->popup( pos );
337        }
338        //else if ( m_pSoundLibraryTree->currentItem()->parent()->parent()->parent() ==  m_pPatternItemList ) {
339        //      m_pPatternMenuList->popup( pos );
340        //}
341       
342
343        if ( m_pSoundLibraryTree->currentItem()->parent() == m_pSystemDrumkitsItem ) {
344                m_pDrumkitMenu->popup( pos );
345        }
346        else if ( m_pSoundLibraryTree->currentItem()->parent()->parent() == m_pSystemDrumkitsItem ) {
347                m_pInstrumentMenu->popup( pos );
348        }
349}
350
351
352
353void SoundLibraryPanel::on_DrumkitList_leftClicked( QPoint pos )
354{
355        m_startDragPosition = pos;
356}
357
358
359
360void SoundLibraryPanel::on_DrumkitList_mouseMove( QMouseEvent *event)
361{
362       
363       
364        if (! ( event->buttons() & Qt::LeftButton ) ) {
365                return;
366        }
367
368       
369        if ( ( event->pos() - m_startDragPosition ).manhattanLength() < QApplication::startDragDistance() ) {
370                return;
371        }
372       
373        if ( !m_pSoundLibraryTree->currentItem() ) {
374                return;
375        }
376       
377        if (
378                ( m_pSoundLibraryTree->currentItem()->parent() == m_pSystemDrumkitsItem ) ||
379                ( m_pSoundLibraryTree->currentItem()->parent() == m_pUserDrumkitsItem )
380        ) {
381                // drumkit selection
382                //INFOLOG( "ho selezionato un drumkit (system)" );
383                return;
384        }
385       
386        else {
387                //INFOLOG( "ho selezionato uno strumento" );
388                // instrument selection
389                if ( m_pSoundLibraryTree->currentItem() == NULL )
390                {
391                        return;
392                }
393               
394                if ( m_pSoundLibraryTree->currentItem()->parent() == NULL )
395                {
396                        return;
397                }       
398
399                if ( m_pSoundLibraryTree->currentItem()->parent()->text(0) == NULL )
400                {
401                        return;
402                }
403               
404
405                QString sDrumkitName = m_pSoundLibraryTree->currentItem()->parent()->text(0);
406                QString sInstrumentName = ( m_pSoundLibraryTree->currentItem()->text(0) ).remove( 0, m_pSoundLibraryTree->currentItem()->text(0).indexOf( "] " ) + 2 );
407
408                QString sText = sDrumkitName + "::" + sInstrumentName;
409
410                QDrag *pDrag = new QDrag(this);
411                QMimeData *pMimeData = new QMimeData;
412
413                pMimeData->setText( sText );
414                pDrag->setMimeData( pMimeData);
415                //drag->setPixmap(iconPixmap);
416
417                pDrag->start( Qt::CopyAction | Qt::MoveAction );
418        }
419       
420}
421
422
423
424void SoundLibraryPanel::on_drumkitLoadAction()
425{
426        QString sDrumkitName = m_pSoundLibraryTree->currentItem()->text(0);
427
428        Drumkit *drumkitInfo = NULL;
429
430        // find the drumkit in the list
431        for ( uint i = 0; i < m_systemDrumkitInfoList.size(); i++ ) {
432                Drumkit *pInfo = m_systemDrumkitInfoList[i];
433                if ( pInfo->getName() == sDrumkitName ) {
434                        drumkitInfo = pInfo;
435                        break;
436                }
437        }
438        for ( uint i = 0; i < m_userDrumkitInfoList.size(); i++ ) {
439                Drumkit*pInfo = m_userDrumkitInfoList[i];
440                if ( pInfo->getName() == sDrumkitName ) {
441                        drumkitInfo = pInfo;
442                        break;
443                }
444        }
445        assert( drumkitInfo );
446
447
448        setCursor( QCursor( Qt::WaitCursor ) );
449
450        Hydrogen::get_instance()->loadDrumkit( drumkitInfo );
451        Hydrogen::get_instance()->getSong()->__is_modified = true;
452        HydrogenApp::getInstance()->setStatusBarMessage( trUtf8( "Drumkit loaded: [%1]" ).arg( drumkitInfo->getName() ), 2000 );
453
454        setCursor( QCursor( Qt::ArrowCursor ) );
455
456        // update drumkit info in save tab
457        //saveTab_nameTxt ->setText( QString( drumkitInfo->getName().c_str() ) );
458        //saveTab_authorTxt->setText( QString( drumkitInfo->getAuthor().c_str() ) );
459        //saveTab_infoTxt->append( QString( drumkitInfo->getInfo().c_str() ) );
460
461//      HydrogenApp::getInstance()->getPatternEditorPanel()->getPatternEditor()->updateEditor( true );
462
463//HydrogenApp::getInstance()->getPatternEditorPanel()->getDrumPatternEditor()->updateEditor();
464}
465
466
467
468void SoundLibraryPanel::on_drumkitDeleteAction()
469{
470        QString sSoundLibrary = m_pSoundLibraryTree->currentItem()->text( 0 );
471
472        //if we delete the current loaded drumkit we can get truble with some empty pointers
473        if ( sSoundLibrary == Hydrogen::get_instance()->getCurrentDrumkitname() ){
474                QMessageBox::warning( this, "Hydrogen", QString( "You try to delet the current loaded drumkit.\nThis is not possible!") );
475                return;
476        }
477
478        bool bIsUserSoundLibrary = false;
479        std::vector<QString> userList = Drumkit::getUserDrumkitList();
480        for ( uint i = 0; i < userList.size(); ++i ) {
481                if ( userList[ i ].endsWith( sSoundLibrary ) ) {
482                        bIsUserSoundLibrary = true;
483                        break;
484                }
485        }
486
487        if ( bIsUserSoundLibrary == false ) {
488                QMessageBox::warning( this, "Hydrogen", QString( "A system drumkit can't be deleted.") );
489                return;
490        }
491
492        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 );
493        if ( res == 1 ) {
494                return;
495        }
496
497        Drumkit::removeDrumkit( sSoundLibrary );
498
499        HydrogenApp::getInstance()->getInstrumentRack()->getSoundLibraryPanel()->updateDrumkitList();
500}
501
502
503
504void SoundLibraryPanel::on_drumkitExportAction()
505{
506        SoundLibraryExportDialog exportDialog( this );
507        exportDialog.exec();
508}
509
510
511
512void SoundLibraryPanel::on_drumkitPropertiesAction()
513{
514
515        QString sDrumkitName = m_pSoundLibraryTree->currentItem()->text(0);
516
517        Drumkit *drumkitInfo = NULL;
518       
519
520        // find the drumkit in the list
521        for ( uint i = 0; i < m_systemDrumkitInfoList.size(); i++ ) {
522                Drumkit *pInfo = m_systemDrumkitInfoList[i];
523                if ( pInfo->getName() == sDrumkitName ) {
524                        drumkitInfo = pInfo;
525                        break;
526                }
527        }
528        for ( uint i = 0; i < m_userDrumkitInfoList.size(); i++ ) {
529                Drumkit*pInfo = m_userDrumkitInfoList[i];
530                if ( pInfo->getName() == sDrumkitName ) {
531                        drumkitInfo = pInfo;
532                        break;
533                }
534        }
535
536        assert( drumkitInfo );
537
538
539        QString sPreDrumkitName = Hydrogen::get_instance()->getCurrentDrumkitname();
540
541        Drumkit *preDrumkitInfo = NULL;
542       
543
544        // find the drumkit in the list
545        for ( uint i = 0; i < m_systemDrumkitInfoList.size(); i++ ) {
546                Drumkit *prInfo = m_systemDrumkitInfoList[i];
547                if ( prInfo->getName() == sPreDrumkitName ) {
548                        preDrumkitInfo = prInfo;
549                        break;
550                }
551        }
552        for ( uint i = 0; i < m_userDrumkitInfoList.size(); i++ ) {
553                Drumkit *prInfo = m_userDrumkitInfoList[i];
554                if ( prInfo->getName() == sPreDrumkitName ) {
555                        preDrumkitInfo = prInfo;
556                        break;
557                }
558        }
559
560        assert( preDrumkitInfo );
561       
562        //open the soundlibrary save dialog
563        SoundLibraryPropertiesDialog dialog( this , drumkitInfo, preDrumkitInfo );
564        dialog.exec();
565
566}
567
568
569
570void SoundLibraryPanel::on_instrumentDeleteAction()
571{
572        QMessageBox::warning( this, "Hydrogen", QString( "Not implemented yet.") );
573        ERRORLOG( "[on_instrumentDeleteAction] not implemented yet" );
574}
575
576void SoundLibraryPanel::on_songLoadAction()
577{
578        QString songName = m_pSoundLibraryTree->currentItem()->text( 0 );
579        QString sDirectory = Preferences::getInstance()->getDataDirectory()  + "songs";
580
581        QString sFilename = sDirectory + "/" + songName + ".h2song";
582       
583
584        Hydrogen *engine = Hydrogen::get_instance();
585        if ( engine->getState() == STATE_PLAYING ) {
586                engine->sequencer_stop();
587        }
588
589        H2Core::LocalFileMng mng;
590        Song *pSong = Song::load( sFilename );
591        if ( pSong == NULL ) {
592                QMessageBox::information( this, "Hydrogen", trUtf8("Error loading song.") );
593                return;
594        }
595
596        // add the new loaded song in the "last used song" vector
597        Preferences *pPref = Preferences::getInstance();
598
599        std::vector<QString> recentFiles = pPref->getRecentFiles();
600        recentFiles.insert( recentFiles.begin(), sFilename );
601        pPref->setRecentFiles( recentFiles );
602
603        HydrogenApp* h2app = HydrogenApp::getInstance();
604
605        h2app->setSong( pSong );
606
607        //updateRecentUsedSongList();
608        engine->setSelectedPatternNumber( 0 );
609}
610
611
612
613void SoundLibraryPanel::on_patternLoadAction()
614{
615
616        LocalFileMng mng;
617
618        QString patternName = m_pSoundLibraryTree->currentItem()->text( 0 );
619        Hydrogen *engine = Hydrogen::get_instance();
620        Song *song = engine->getSong();
621        PatternList *pPatternList = song->get_pattern_list();
622       
623        QString sDirectory = "";
624
625        std::vector<QString> patternDirList = mng.getPatternDirList();
626
627                for (uint i = 0; i < patternDirList.size(); ++i) {
628                        QString absPath =  patternDirList[i];
629                        mng.getPatternList( absPath );
630                }
631
632        std::vector<QString> allPatternDirList = mng.getallPatternList();//full pattern path list
633
634        for (uint i = 0; i < allPatternDirList.size(); ++i) {
635                QString testName = allPatternDirList[i];
636                if( testName.contains( patternName )){
637
638                        sDirectory = allPatternDirList[i];
639               
640                }
641        }
642
643        Pattern* err = mng.loadPattern (sDirectory );
644
645        if ( err == 0 )
646        {
647                _ERRORLOG ( "Error loading the pattern" );
648        }
649        else
650        {
651                H2Core::Pattern *pNewPattern = err;
652                pPatternList->add ( pNewPattern );
653                song->__is_modified = true;
654        }
655
656        HydrogenApp::getInstance()->getSongEditorPanel()->updateAll();
657}
658
Note: See TracBrowser for help on using the browser.