35#include <QFileSystemModel>
43 bool bShowInstrumentManipulationControls,
45 const QString& sFilename )
48 , m_sFilename( sFilename )
52 setWindowTitle ( tr (
"Audio File Browser" ) );
54 setFixedSize ( width(), height() );
56 if ( sDefaultPath.isEmpty() ) {
57 sDefaultPath = QDir::homePath();
66 m_pDirModel->setFilter( QDir::AllDirs | QDir::AllEntries | QDir::NoDotAndDotDot );
67 m_pDirModel->setNameFilters( QStringList() <<
"*.ogg" <<
"*.OGG" <<
"*.wav" <<
"*.WAV" <<
"*.flac"<<
"*.FLAC" <<
"*.aiff" <<
"*.AIFF"<<
"*.au" <<
"*.AU" );
72 m_pPlayBtn->setEnabled(
false );
73 m_pStopBtn->setEnabled(
false );
74 openBTN->setEnabled(
false );
76 m_pTree =
new QTreeView( treeView );
79 m_pTree->header()->resizeSection( 0, 405 );
80 m_pTree->setAlternatingRowColors(
true );
83 pathLineEdit->setText( sDefaultPath );
90 m_pPathUptoolButton->setToolTip( QString( tr(
"Parent Folder" )));
92 m_pPathHometoolButton->setToolTip( QString( tr(
"Home" )));
95 m_pPlayBtn->setToolTip( QString( tr(
"Play selected" ) ));
97 m_pStopBtn->setToolTip( QString( tr(
"Stop" )));
109 useNameCheckBox->hide();
110 autoVelCheckBox->hide();
113 if ( ! sFilename.isEmpty() ) {
125 QTimer::singleShot( 50, [
this]{
127 QAbstractItemView::PositionAtCenter);} );
132 connect( pathLineEdit, SIGNAL( returnPressed() ), SLOT(
updateModelIndex() ) );
148 ( filename.endsWith(
".ogg" ) ) ||
149 ( filename.endsWith(
".OGG" ) ) ||
150 ( filename.endsWith(
".wav" ) ) ||
151 ( filename.endsWith(
".WAV" ) ) ||
152 ( filename.endsWith(
".au" ) ) ||
153 ( filename.endsWith(
".AU" ) ) ||
154 ( filename.endsWith(
".aiff" ) ) ||
155 ( filename.endsWith(
".AIFF" ) ) ||
156 ( filename.endsWith(
".flac" ) ) ||
157 ( filename.endsWith(
".FLAC" ) )
168 QString desktopSession = getenv(
"DESKTOP_SESSION");
170 if( desktopSession ==
"kde" ) {
171 QFile envfile( QDir::homePath() +
"/.kde/share/config/kdeglobals");
173 if ( !envfile.open(QIODevice::ReadOnly | QIODevice::Text) ) {
177 QTextStream envin( &envfile );
178 while ( !envin.atEnd() ) {
179 QString envLine = envin.readLine();
180 if( envLine == QString(
"SingleClick=true" ) ) {
194 if( ( ev->modifiers()==Qt::ControlModifier ||
195 ev->modifiers()==Qt::ShiftModifier )
197 m_pTree->setSelectionMode( QAbstractItemView::ExtendedSelection );
198 openBTN->setEnabled(
true );
206 m_pTree->setSelectionMode( QAbstractItemView::SingleSelection );
214 QString newPath = pathLineEdit->text();
216 if( QDir( newPath ).exists() ) {
219 toRemove = newPath.section(
'/', -1 );
221 newPath.replace( toRemove,
"" );
256 pathLineEdit->setText( path );
262 m_pPlayBtn->setEnabled(
false );
263 openBTN->setEnabled(
false );
267 QString name = path.section(
'/', -1 );
269 QString path2 = path;
270 QString onlyPath = path;
272 onlyPath = path.replace( name,
"" );
275 name = name.left(
'.' );
277 QString message = QString( tr(
"Name: " ) ).append( name );
278 pathLineEdit->setText( onlyPath );
280 QStringList path2List = path2.split(
"/");
281 QString fleTxt = path2List.last();
283 QApplication::setOverrideCursor(Qt::WaitCursor);
288 filelineedit->setText( fleTxt );
291 if ( pNewSample !=
nullptr ) {
292 m_pNBytesLable->setText( tr(
"Size: %1 bytes" ).arg( pNewSample->get_size() / 2 ) );
293 m_pSamplerateLable->setText( tr(
"Samplerate: %1" ).arg( pNewSample->get_sample_rate() ) );
294 float sec = ( float )( pNewSample->get_frames() / (float)pNewSample->get_sample_rate() );
296 qsec = QString::asprintf(
"%2.2f", sec );
297 m_pLengthLable->setText( tr(
"Sample length: " ) + qsec + tr(
" s" ) );
302 m_pPlayBtn->setEnabled(
true );
303 openBTN->setEnabled(
true );
307 if (playSamplescheckBox->isChecked()){
312 QMessageBox::information (
this,
"Hydrogen", tr(
"Please do not preview samples which are longer than 10 minutes!" ) );
315 m_pNameLabel->setText( message );
317 openBTN->setEnabled(
false );
318 QMessageBox::information (
this,
"Hydrogen", tr(
"Unable to load that sample file." ) );
322 m_pNameLabel->setText( tr(
"Name:"));
323 m_pNBytesLable->setText( tr(
"Size:" ) );
324 m_pSamplerateLable->setText( tr(
"Samplerate:" ) );
325 m_pLengthLable->setText( tr(
"Sample length:" ) );
327 m_pPlayBtn->setEnabled(
false );
328 m_pStopBtn->setEnabled(
false );
329 openBTN->setEnabled(
false );
332 QApplication::restoreOverrideCursor();
344 m_pStopBtn->setEnabled(
true );
348 assert(pNewSample->get_sample_rate() != 0);
350 int length = ( ( pNewSample->get_frames() / pNewSample->get_sample_rate() + 1) * 100 );
361 m_pStopBtn->setEnabled(
false );
377 if(
m_pTree->selectionModel()->selectedRows().size() > 0) {
378 QList<QModelIndex>::iterator i;
379 QList<QModelIndex> list =
m_pTree->selectionModel()->selectedRows();
381 for (i = list.begin(); i != list.end(); ++i) {
382 QString path2 = (*i).data().toString();
384 QString path = pathLineEdit->text();
386 if(! path.endsWith(
"/")) {
390 QString act_filename = path + path2;
411 if ( useNameCheckBox->isChecked() ) {
414 if ( autoVelCheckBox->isChecked() ) {
427 QString path = pathLineEdit->text();
428 QStringList pathlist = path.split(
"/");
430 while( path != QDir::rootPath() ){
432 if( pathlist.isEmpty () ) {
436 pathlist.removeLast();
437 QString updir = pathlist.join(
"/");
439 pathLineEdit->setText( updir );
443 path = pathLineEdit->text();
446 pathLineEdit->setText( QDir::homePath() );
456 QString path = pathLineEdit->text();
457 QStringList pathlist = path.split(
"/");
459 if( pathlist.isEmpty () ) {
463 if( path.endsWith(
"/" ) ) {
464 pathlist.removeLast();
465 QString tmpupdir = pathlist.join(
"/");
471 pathlist.removeLast();
473 QString updir = pathlist.join(
"/");
475 pathLineEdit->setText( QString(
"/") );
477 pathLineEdit->setText( updir );
489 if ( hiddenCB->isChecked() ) {
490 m_pDirModel->setFilter( QDir::AllDirs | QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden );
492 m_pDirModel->setFilter( QDir::AllDirs | QDir::AllEntries | QDir::NoDotAndDotDot );
void doubleClicked(const QModelIndex &index)
virtual void keyReleaseEvent(QKeyEvent *ev) override
QFileSystemModel * m_pDirModel
AudioFileBrowser(QWidget *pParent, bool bAllowMultiSelect, bool bShowInstrumentManipulationControls, QString sDefaultPath="", const QString &sFilename="")
QString getSelectedDirectory()
void on_openBTN_clicked()
QStringList getSelectedFiles()
void on_hiddenCB_clicked()
void clicked(const QModelIndex &index)
void on_m_pPathUptoolButton_clicked()
virtual void keyPressEvent(QKeyEvent *ev) override
QString m_sEmptySampleFilename
bool isFileSupported(QString filename)
void on_m_pPlayBtn_clicked()
bool m_bShowInstrumentManipulationControls
void on_m_pStopBtn_clicked()
void on_cancelBTN_clicked()
void on_playSamplescheckBox_clicked()
QString m_sSelectedDirectory
void on_m_pPathHometoolButton_clicked()
SampleWaveDisplay * m_pSampleWaveDisplay
QString m_pSampleFilename
void browseTree(const QModelIndex &index)
QStringList m_pSelectedFile
Sampler * getSampler() const
static QString empty_sample_path()
returns system empty sample file path
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
AudioEngine * getAudioEngine() const
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
bool __playsamplesonclicking
static std::shared_ptr< Sample > load(const QString &filepath, const License &license=License())
void preview_sample(std::shared_ptr< Sample > pSample, int length)
Preview, uses only the first layer.
void updateDisplay(QString filename)
static QString getSvgImagePath()