35#include <QFileSystemModel>
43 bool bShowInstrumentManipulationControls,
45 const QString& sFilename )
55 setWindowFlags( windowFlags() | Qt::CustomizeWindowHint |
56 Qt::WindowMinMaxButtonsHint );
58 setWindowTitle ( tr (
"Audio File Browser" ) );
60 if ( sDefaultPath.isEmpty() ) {
61 sDefaultPath = QDir::homePath();
68 QStringList nameFilters;
70 const QString ssFilter = QString(
"*.%1" )
72 nameFilters << ssFilter << ssFilter.toUpper();
77 m_pDirModel->setFilter( QDir::AllDirs | QDir::AllEntries | QDir::NoDotAndDotDot );
83 m_pPlayBtn->setEnabled(
false );
84 m_pStopBtn->setEnabled(
false );
85 openBTN->setEnabled(
false );
88 m_pTree->header()->resizeSection( 0, 405 );
89 m_pTree->setAlternatingRowColors(
true );
90 m_pTree->setRootIndex(
m_pDirModel->index( sDefaultPath ) );
92 pathLineEdit->setText( sDefaultPath );
99 m_pPathUptoolButton->setToolTip( QString( tr(
"Parent Folder" )));
101 m_pPathHometoolButton->setToolTip( QString( tr(
"Home" )));
104 m_pPlayBtn->setToolTip( QString( tr(
"Play selected" ) ));
106 m_pStopBtn->setToolTip( QString( tr(
"Stop" )));
118 useNameCheckBox->hide();
119 autoVelCheckBox->hide();
122 if ( ! sFilename.isEmpty() ) {
123 m_pTree->setCurrentIndex(
m_pDirModel->index( sFilename ) );
134 QTimer::singleShot( 50, [
this]{
136 QAbstractItemView::PositionAtCenter);} );
139 connect( m_pTree, SIGNAL(
clicked(
const QModelIndex&) ), SLOT(
clicked(
const QModelIndex& ) ) );
141 connect( pathLineEdit, SIGNAL( returnPressed() ), SLOT(
updateModelIndex() ) );
163 QString desktopSession = getenv(
"DESKTOP_SESSION");
165 if( desktopSession ==
"kde" ) {
166 QFile envfile( QDir::homePath() +
"/.kde/share/config/kdeglobals");
168 if ( !envfile.open(QIODevice::ReadOnly | QIODevice::Text) ) {
172 QTextStream envin( &envfile );
173 while ( !envin.atEnd() ) {
174 QString envLine = envin.readLine();
175 if( envLine == QString(
"SingleClick=true" ) ) {
189 if( ( ev->modifiers()==Qt::ControlModifier ||
190 ev->modifiers()==Qt::ShiftModifier )
192 m_pTree->setSelectionMode( QAbstractItemView::ExtendedSelection );
193 openBTN->setEnabled(
true );
201 m_pTree->setSelectionMode( QAbstractItemView::SingleSelection );
209 QString newPath = pathLineEdit->text();
211 if( QDir( newPath ).exists() ) {
212 m_pTree->setRootIndex(
m_pDirModel->index( newPath ) );
214 toRemove = newPath.section(
'/', -1 );
216 newPath.replace( toRemove,
"" );
217 m_pTree->setRootIndex(
m_pDirModel->index( newPath ) );
251 pathLineEdit->setText( path );
257 m_pPlayBtn->setEnabled(
false );
258 openBTN->setEnabled(
false );
262 QString name = path.section(
'/', -1 );
264 QString path2 = path;
265 QString onlyPath = path;
267 onlyPath = path.replace( name,
"" );
270 name = name.left(
'.' );
272 QString message = QString( tr(
"Name: " ) ).append( name );
273 pathLineEdit->setText( onlyPath );
275 QStringList path2List = path2.split(
"/");
276 QString fleTxt = path2List.last();
278 QApplication::setOverrideCursor(Qt::WaitCursor);
282 filelineedit->setText( fleTxt );
285 if ( pNewSample !=
nullptr ) {
286 m_pNBytesLable->setText( tr(
"Size: %1 bytes" ).arg( pNewSample->get_size() / 2 ) );
287 m_pSamplerateLable->setText( tr(
"Samplerate: %1" ).arg( pNewSample->get_sample_rate() ) );
288 float sec = ( float )( pNewSample->get_frames() / (
float)pNewSample->get_sample_rate() );
290 qsec = QString::asprintf(
"%2.2f", sec );
291 m_pLengthLable->setText( tr(
"Sample length: " ) + qsec + tr(
" s" ) );
296 m_pPlayBtn->setEnabled(
true );
297 openBTN->setEnabled(
true );
301 if (playSamplescheckBox->isChecked()){
306 QMessageBox::information (
this,
"Hydrogen", tr(
"Please do not preview samples which are longer than 10 minutes!" ) );
309 m_pNameLabel->setText( message );
311 openBTN->setEnabled(
false );
312 QMessageBox::information (
this,
"Hydrogen", tr(
"Unable to load that sample file." ) );
316 m_pNameLabel->setText( tr(
"Name:"));
317 m_pNBytesLable->setText( tr(
"Size:" ) );
318 m_pSamplerateLable->setText( tr(
"Samplerate:" ) );
319 m_pLengthLable->setText( tr(
"Sample length:" ) );
321 m_pPlayBtn->setEnabled(
false );
322 m_pStopBtn->setEnabled(
false );
323 openBTN->setEnabled(
false );
326 QApplication::restoreOverrideCursor();
338 m_pStopBtn->setEnabled(
true );
342 assert(pNewSample->get_sample_rate() != 0);
344 int length = ( ( pNewSample->get_frames() / pNewSample->get_sample_rate() + 1) * 100 );
355 m_pStopBtn->setEnabled(
false );
371 if ( m_pTree->selectionModel()->selectedRows().size() > 0 ) {
372 QList<QModelIndex>::iterator i;
373 QList<QModelIndex> list = m_pTree->selectionModel()->selectedRows();
375 for (i = list.begin(); i != list.end(); ++i) {
376 QString path2 = (*i).data().toString();
378 QString path = pathLineEdit->text();
380 if (! path.endsWith(
"/") ) {
384 QString act_filename = path + path2;
405 if ( useNameCheckBox->isChecked() ) {
408 if ( autoVelCheckBox->isChecked() ) {
421 QString path = pathLineEdit->text();
422 QStringList pathlist = path.split(
"/");
424 while( path != QDir::rootPath() ){
426 if( pathlist.isEmpty () ) {
430 pathlist.removeLast();
431 QString updir = pathlist.join(
"/");
433 pathLineEdit->setText( updir );
434 m_pTree->setRootIndex(
m_pDirModel->index( updir ) );
436 m_pTree->setExpanded(
m_pDirModel->index(updir),
false );
437 path = pathLineEdit->text();
440 pathLineEdit->setText( QDir::homePath() );
441 m_pTree->setRootIndex(
m_pDirModel->index( QDir::homePath() ) );
443 m_pTree->collapse(
m_pDirModel->index( QDir::homePath()) );
450 QString path = pathLineEdit->text();
451 QStringList pathlist = path.split(
"/");
453 if( pathlist.isEmpty () ) {
457 if( path.endsWith(
"/" ) ) {
458 pathlist.removeLast();
459 QString tmpupdir = pathlist.join(
"/");
460 m_pTree->setRootIndex(
m_pDirModel->index( tmpupdir ) );
461 m_pTree->collapse(
m_pDirModel->index( tmpupdir ) );
462 m_pTree->setExpanded(
m_pDirModel->index( tmpupdir ),
false );
465 pathlist.removeLast();
467 QString updir = pathlist.join(
"/");
469 pathLineEdit->setText( QString(
"/") );
471 pathLineEdit->setText( updir );
474 m_pTree->setRootIndex(
m_pDirModel->index( updir ) );
476 m_pTree->setExpanded(
m_pDirModel->index(updir),
false );
483 if ( hiddenCB->isChecked() ) {
484 m_pDirModel->setFilter( QDir::AllDirs | QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden );
486 m_pDirModel->setFilter( QDir::AllDirs | QDir::AllEntries | QDir::NoDotAndDotDot );
487 m_pTree->setRootIndex(
m_pDirModel->index( pathLineEdit->text() ) );
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 AudioFormat AudioFormatFromSuffix(const QString &sFile, bool bSilent=false)
Determines the audio format of the provided filename or path based on its suffix.
static QString empty_sample_path()
returns system empty sample file path
static bool file_exists(const QString &path, bool silent=false)
returns true if the given path is an existing regular file
static const std::vector< AudioFormat > & supportedAudioFormats()
Which format is supported is determined by the libsndfile version Hydrogen is linked against during c...
static QString AudioFormatToSuffix(const AudioFormat &format, bool bSilent=false)
Converts format to the default lower case suffix of the format.
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.
static QString getSvgImagePath()