root/branches/audiofilebrowser/gui/src/AudioFileBrowser/AudioFileBrowser.cpp @ 481

Revision 481, 4.5 KB (checked in by wolke, 5 years ago)

audiofilbrowser next step

RevLine 
[475]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
24#include "AudioFileBrowser.h"
25#include "../HydrogenApp.h"
[480]26#include "InstrumentEditor/InstrumentEditor.h"
[475]27
28#include <hydrogen/LocalFileMng.h>
29#include <hydrogen/h2_exception.h>
30#include <hydrogen/Preferences.h>
31#include <hydrogen/hydrogen.h>
[481]32#include <hydrogen/sample.h>
[475]33
34#include "../widgets/Button.h"
35
36#include <QTreeWidget>
37#include <QDomDocument>
38#include <QMessageBox>
39#include <QHeaderView>
40#include <QFileDialog>
41#include <vector>
42#include <cstdlib>
43#include <iostream>
44#include <fstream>
45
46using namespace H2Core;
47using namespace std;
48
49AudioFileBrowser::AudioFileBrowser ( QWidget* pParent )
50                : QDialog ( pParent )
51                , Object ( "AudioFileBrowser" )
52{
53
54        setupUi ( this );
55        INFOLOG ( "INIT" );
56        setWindowTitle ( trUtf8 ( "Audio File Browser" ) );
57        setFixedSize ( width(), height() );
58        installEventFilter(this);
59
[480]60
61        model = new QDirModel();
62        model->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot );
63        model->setSorting(QDir::DirsFirst |QDir::Name);
64        QModelIndex index = model->index(QDir::currentPath());
[481]65       
66        m_pPlayBtn->setEnabled( false );
[480]67
68
69//      namelabel->setText(model->headerData());
70        QTreeView *tree = new QTreeView(treeView);
71        tree->setModel(model);
72        tree->resize(799, 310);
[481]73        tree->header()->resizeSection ( 0, 405 );
[480]74        tree->setRootIndex(model->index(QDir::homePath()));
75
[481]76        m_psamplefilename = "";
77        m_pselectedFile = "";
[480]78
79        connect(tree, SIGNAL(clicked(const QModelIndex&)), SLOT(clicked(const QModelIndex&)));
80
[475]81}
82
83
84AudioFileBrowser::~AudioFileBrowser()
85{
86        INFOLOG ( "DESTROY" );
87}
88
[480]89
90void AudioFileBrowser::clicked(const QModelIndex& index)
91{
[481]92
93        QString path = model->filePath(index);
94        filelineedit->setText(path);
[480]95        if ( model->isDir(index))
96                 return;
[481]97
98        QString name = path.section( '/', -1 );
99        name = name.left('.');
100
101        QString message = "Name: " + name;
102        filelineedit->setText(path);
103
104//      QString fileinfo = model->fileInfo(index);
105
[480]106        if      (
107                ( path.endsWith( ".wav" ) ) ||
108                ( path.endsWith( ".WAV" ) ) ||
109                ( path.endsWith( ".au" ) ) ||
110                ( path.endsWith( ".AU" ) ) ||
111                ( path.endsWith( ".aiff" ) ) ||
112                ( path.endsWith( ".AIFF" ) ) ||
113                ( path.endsWith( ".flac" ) ) ||
114                ( path.endsWith( ".FLAC" ) )
115                ) {
[481]116
117                        Sample *pNewSample = Sample::load( path );
118                        if (pNewSample) {
119                                m_pNBytesLable->setText( trUtf8( "Size: %1 bytes" ).arg( pNewSample->get_size() ) );
120                                m_pSamplerateLable->setText( trUtf8( "Samplerate: %1" ).arg( pNewSample->get_sample_rate() ) );
121                                m_pLengthLable->setText( trUtf8( "Samplelength: %1 s" ).arg( pNewSample->get_n_frames() / pNewSample->get_sample_rate() ) );
122
123                                delete pNewSample;
124                                m_pPlayBtn->setEnabled( true );
125                                m_psamplefilename = path;
126                        }               
127                        m_pNameLabel->setText(message);                 
128                }else{
129                        m_pNameLabel->setText( trUtf8( "Name:"));
130                        m_pNBytesLable->setText( trUtf8( "Size:" ) );
131                        m_pSamplerateLable->setText( trUtf8( "Samplerate:" ) );
132                        m_pLengthLable->setText( trUtf8( "Samplelength:" ) );
133                        m_pPlayBtn->setEnabled( false );
134                        m_psamplefilename = "";
[480]135                }
136}
137
138
[481]139void AudioFileBrowser::on_m_pPlayBtn_clicked()
140{
141}
142
[480]143void AudioFileBrowser::on_cancelBTN_clicked()
144{
145        m_pselectedFile = "";
146        reject();
147}
148
149
150void AudioFileBrowser::on_openBTN_clicked()
151{
[481]152        if      (
153                ( ( filelineedit->text().endsWith( ".wav" ) ) ||
154                ( filelineedit->text().endsWith( ".WAV" ) ) ||
155                ( filelineedit->text().endsWith( ".au" ) ) ||
156                ( filelineedit->text().endsWith( ".AU" ) ) ||
157                ( filelineedit->text().endsWith( ".aiff" ) ) ||
158                ( filelineedit->text().endsWith( ".AIFF" ) ) ||
159                ( filelineedit->text().endsWith( ".flac" ) ) ||
160                ( filelineedit->text().endsWith( ".FLAC" ) ) ) &&
161                ( QFile( filelineedit->text() ).exists() == true )
162                ) {             
163                        m_pselectedFile = filelineedit->text();
164                       
165                }else
166                {
167                        m_pselectedFile = "";
168                }
[480]169        accept();
170}
171
172
173QString AudioFileBrowser::selectedFile()
174{
175        return m_pselectedFile;
176}
Note: See TracBrowser for help on using the browser.