aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Input/modplug/decoder_modplug.h
blob: 53b175149280a436a43646fc765e00c6b252335c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/***************************************************************************
 *   Copyright (C) 2008-2009 by Ilya Kotov                                 *
 *   forkotov02@hotmail.ru                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#ifndef DECODER_MODPLUG_H
#define DECODER_MODPLUG_H

#include <qmmp/decoder.h>

class CSoundFile;

class DecoderModPlug : public Decoder
{
public:
    DecoderModPlug(const QString &path);
    virtual ~DecoderModPlug();

    void readSettings();
    static DecoderModPlug* instance();
    // Standard Decoder API
    bool initialize();
    qint64 totalTime();
    int bitrate();
    qint64 read(char *audio, qint64 maxSize);
    void seek(qint64 time);

private:

    //helper function
    void deinit();

    CSoundFile *m_soundFile;

    int m_bps; //bits per sample
    QByteArray m_input_buf; //input buffer
    quint32 m_freq;
    int m_chan, m_sampleSize, m_bitrate;
    qint64 m_totalTime;
    double m_preampFactor;
    bool m_usePreamp;
    QString m_path;
    static DecoderModPlug* m_instance;
};

#endif // DECODER_MODPLUG_H
pre>
806aa8dd1


912dd0717
806aa8dd1
3206842d6
806aa8dd1

3206842d6







1e31fe896
3206842d6





806aa8dd1


1e31fe896
3206842d6


806aa8dd1
3206842d6
806aa8dd1

ac64d9ea0
806aa8dd1


3206842d6





806aa8dd1








ac64d9ea0
806aa8dd1
ef99559c8


806aa8dd1
ef99559c8







1e31fe896
ef99559c8



806aa8dd1

ef99559c8



806aa8dd1
ef99559c8










912dd0717

ef99559c8
1e31fe896
806aa8dd1
1e31fe896
806aa8dd1
ef99559c8

806aa8dd1

806aa8dd1


ac64d9ea0
806aa8dd1





ef99559c8
806aa8dd1
ef99559c8
806aa8dd1
ef99559c8
48698c0f1
ef99559c8
806aa8dd1

ac64d9ea0
806aa8dd1
48698c0f1
806aa8dd1
48698c0f1



806aa8dd1

48698c0f1
806aa8dd1
48698c0f1




806aa8dd1
48698c0f1
806aa8dd1
48698c0f1
806aa8dd1
48698c0f1

806aa8dd1

48698c0f1
806aa8dd1
48698c0f1
806aa8dd1
48698c0f1


806aa8dd1
48698c0f1








806aa8dd1

ac64d9ea0
806aa8dd1
3206842d6


806aa8dd1
3206842d6
912dd0717
3206842d6
806aa8dd1

ef99559c8

912dd0717


ef99559c8
912dd0717

ef99559c8


912dd0717
806aa8dd1























806aa8dd1
1742aa3b1
48698c0f1
806aa8dd1


1742aa3b1
912dd0717

806aa8dd1





912dd0717
806aa8dd1

806aa8dd1




3206842d6
806aa8dd1









806aa8dd1







1742aa3b1
806aa8dd1

3206842d6
806aa8dd1
3206842d6
806aa8dd1
3206842d6






806aa8dd1
3206842d6

806aa8dd1
806aa8dd1

ac64d9ea0
806aa8dd1




3206842d6
806aa8dd1
3206842d6

806aa8dd1

ac64d9ea0
806aa8dd1





1e31fe896
806aa8dd1







ac64d9ea0
806aa8dd1

ac64d9ea0

806aa8dd1


ac64d9ea0
806aa8dd1















912dd0717
806aa8dd1
806aa8dd1

912dd0717
3206842d6
806aa8dd1



3206842d6
806aa8dd1
1e31fe896
806aa8dd1











3206842d6
806aa8dd1



ac64d9ea0
3206842d6
806aa8dd1








3206842d6
806aa8dd1








3206842d6
806aa8dd1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471

                                                                           
                                                                           
















                                                                            






                       
                      
                                   

























                                                                                    
                                                                                  

















                                                                                               
                                                                 

                                                                                 




                                                                 
                                                                                            






                                                                                             
                                                 


 
                                                         
 
                  

                                       







                                                                                             
                                                                                           





                                                                        


        
                                                                               


                                                     
     
             

 
                                                                                                


                                 





                                                                     








                                                    
                                                   
 


                                        
     







                                           
                                              



                                                  

     



                          
     










                                            

                                                                                                            
     
                                                  
         
                                        
             

                                                  

             


     
                                                                                 





                                                                              
 
                           
     
                                                  
                                                                          
                                     
     

 
                                                                             
 
                             
     



                                                                

 
                                                                                       
 




                                             
 
                                                                                 
 
                                       
     

                                                     

               
                 
                             
                    
        


                                                                                   
               








                                                                               

 
                                                   
 


                                    
     
                                
                           
     

 

                                                    


                                    
     

                                


     
                                                                                                             























                                                                                   
     
                                                                                  
                                                          


                                                    
                                       

                                                                





                                  
                                   

                                              




                                                
                                                                               









                                                                                         







                                                                                      
                                                                                                  

              
                              
     
                                               
                                            






                                                                                  
     

            
     

 
                                                                     




                                                                             
                                                                                  
 

                                                              

 
                                                                





                                                                 
                                                             







                                                                     
                                                          

                                                                 

                                                                     


                              
                                                              















                                                              
                                                                         
 

                   
                                       
                 



                                            
                                                       
                              
                                                                                            











                                                       
                                                                                        



                                             
                                                                       
                                                       








                                                                                           
                                                                           








                                                                                                 
                 
 
/**************************************************************************
*   Copyright (C) 2016 by Ilya Kotov                                      *
*   forkotov02@ya.ru                                                      *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
***************************************************************************/

#include <QDirModel>
#include <QApplication>
#include <QFileInfo>
#include <QStyle>
#include <QSettings>
#include <QMessageBox>
#include <QHeaderView>
#include <qmmp/qmmp.h>
#include "twopanelfiledialogimpl.h"

#define HISTORY_SIZE 8


/**
 *   This variable has been copied from Qt library
 */

const char *qt_file_dialog_filter_reg_exp =
    "([a-zA-Z0-9 -]*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";

/**
 *   This function has been copied from Qt library
 */

// Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)"
static QStringList qt_clean_filter_list(const QString &filter)
{
    QRegExp regexp(QString::fromLatin1(qt_file_dialog_filter_reg_exp));
    QString f = filter;
    int i = regexp.indexIn(f);
    if (i >= 0)
        f = regexp.cap(2);
    return f.split(QLatin1Char(' '), QString::SkipEmptyParts);
}

TwoPanelFileDialogImpl::TwoPanelFileDialogImpl(QWidget * parent) : QDialog(parent)
{
    m_ui.setupUi(this);
    setAttribute(Qt::WA_QuitOnClose, false);
    m_mode = 0;

    m_dirModel = new QFileSystemModel(this);
    m_dirModel->setReadOnly(true);
    m_ui.dirListView->setModel(m_dirModel);
    m_dirModel->setRootPath("");
    m_dirModel->setFilter(QDir::AllDirs | QDir::NoDot);
    m_dirModel->setNameFilterDisables (false);

    connect(m_ui.dirListView->selectionModel(),
            SIGNAL(selectionChanged (QItemSelection, QItemSelection)),
            SLOT(updateDirSelection (QItemSelection, QItemSelection)));

    connect(m_ui.fileListWidget, SIGNAL(itemSelectionChanged()), SLOT(updateFileSelection ()));

    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    restoreGeometry(settings.value("TwoPanelFileDialog/geometry").toByteArray());
    m_history = settings.value("TwoPanelFileDialog/history").toStringList();
    m_ui.lookInComboBox->addItems(m_history);
    m_ui.lookInComboBox->setMaxCount(HISTORY_SIZE);
    QCompleter* dirCompleter = new QCompleter (m_dirModel, this);
    m_ui.lookInComboBox->setCompleter (dirCompleter);

    if(qApp->style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, nullptr, this))
    {
        m_ui.playButton->setIcon(qApp->style()->standardIcon(QStyle::SP_MediaPlay));
        m_ui.addButton->setIcon(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton));
        m_ui.closeButton->setIcon(qApp->style()->standardIcon(QStyle::SP_DialogCloseButton));
    }
}

TwoPanelFileDialogImpl::~TwoPanelFileDialogImpl()
{
}

QStringList TwoPanelFileDialogImpl::selectedFiles() const
{
    QStringList l;
    if (m_mode == FileDialog::SaveFile)
    {
        QModelIndexList indexes = m_ui.dirListView->selectionModel()->selectedRows(0);
        if(!indexes.isEmpty() && indexes.first().isValid())
        {
            l << m_dirModel->filePath(indexes.first()) + "/" + m_ui.fileNameLineEdit->text();
        }
    }
    else if(m_mode == FileDialog::AddDir || m_mode == FileDialog::AddDirs)
    {
        for(const QModelIndex &index : m_ui.dirListView->selectionModel()->selectedRows(0))
        {
            if(index.isValid() && (m_dirModel->fileName(index) != ".."))
            {
                l << m_dirModel->filePath(index);
            }
        }
    }
    else
    {
        for(const QListWidgetItem *item : m_ui.fileListWidget->selectedItems())
        {
            l << item->data(Qt::UserRole).toString();
        }
    }
    return l;
}

void TwoPanelFileDialogImpl::updateDirSelection(const QItemSelection &s, const QItemSelection &)
{
    m_ui.fileListWidget->clear();

    if(m_mode == FileDialog::AddDir || m_mode == FileDialog::AddDirs)
    {
        m_ui.addButton->setEnabled(!selectedFiles().isEmpty());
        return;
    }

    if(s.indexes().isEmpty())
        return;

    QModelIndex index = s.indexes().first();

    if(index.isValid())
        updateFileList(m_dirModel->filePath(index));
}

void TwoPanelFileDialogImpl::updateFileSelection ()
{
    QStringList paths = selectedFiles();

    if(paths.isEmpty())
    {
        m_ui.fileNameLineEdit->clear();
        m_ui.addButton->setEnabled(false);
        m_ui.playButton->setEnabled(false);
        return;
    }

    QStringList names;

    for(const QString &path : qAsConst(paths))
    {
        QString name = QFileInfo(path).fileName();
        if (!names.contains(name))
            names << name;
    }

    QString str;
    if (names.size() == 1)
        str = names.at(0);
    else
    {
        str = names.join ("\" \"");
        str.append("\"");
        str.prepend("\"");
    }
    if (!m_ui.fileNameLineEdit->hasFocus())
        m_ui.fileNameLineEdit->setText(str);


    m_ui.addButton->setEnabled(true);
    m_ui.playButton->setEnabled(false);

    if(m_mode == FileDialog::AddFiles || m_mode == FileDialog::AddDirsFiles || m_mode == FileDialog::AddFile
            || m_mode == FileDialog::PlayDirsFiles)
    {
        for(const QString &path : qAsConst(paths))
        {
            if(QFileInfo(path).isFile())
            {
                m_ui.playButton->setEnabled(true);
                break;
            }
        }
    }
}

void TwoPanelFileDialogImpl::on_dirListView_doubleClicked(const QModelIndex &ind)
{
    if (!ind.isValid())
        return;

    QFileInfo info = m_dirModel->fileInfo(ind);
    QModelIndex rootIndex = m_dirModel->setRootPath(info.canonicalFilePath());

    if(rootIndex.isValid())
    {
        m_ui.dirListView->setRootIndex(rootIndex);
        m_ui.lookInComboBox->setEditText(m_dirModel->filePath(rootIndex));
        m_ui.fileListWidget->clear();
    }
}

void TwoPanelFileDialogImpl::on_lookInComboBox_activated(const QString &path)
{
    if (QDir(path).exists ())
    {
        m_ui.dirListView->setRootIndex(m_dirModel->index(path));
        m_dirModel->setRootPath(path);
        m_ui.fileListWidget->clear();
    }
}

void TwoPanelFileDialogImpl::on_fileListWidget_itemDoubleClicked(QListWidgetItem *item)
{
    QStringList l;
    l << item->data(Qt::UserRole).toString();
    addToHistory(l[0]);
    addFiles(l, false);
}

void TwoPanelFileDialogImpl::on_fileNameLineEdit_textChanged(const QString &text)
{
    if (m_mode == FileDialog::SaveFile)
    {
        m_ui.addButton->setEnabled(!text.isEmpty());
        m_ui.playButton->setEnabled(!text.isEmpty());
        return;
    }
    QString path;
    if (text.startsWith("/"))
        path = text;
    else
        path = m_dirModel->filePath(m_ui.dirListView->currentIndex()) + "/" + text;

    if (!QFileInfo(path).exists())
        return;

    for(int i = 0; i < m_ui.fileListWidget->count(); ++i)
    {
        if(path == m_ui.fileListWidget->item(i)->data(Qt::UserRole).toString())
        {
            m_ui.fileListWidget->setCurrentRow(i, QItemSelectionModel::Select);
            break;
        }
    }
}

void TwoPanelFileDialogImpl::on_addButton_clicked()
{
    QStringList l = selectedFiles();

    if(!l.isEmpty())
    {
        addToHistory(l.first());
        addFiles(l, false);
    }
}

void TwoPanelFileDialogImpl::on_playButton_clicked()
{
    QStringList l = selectedFiles();

    if(!l.isEmpty())
    {
        addToHistory(l.first());
        addFiles(l, true);
    }
}

void TwoPanelFileDialogImpl::setModeAndMask(const QString& path, FileDialog::Mode m, const QStringList& mask)
{
    m_mode = m;
    m_ui.dirListView->clearSelection();
    m_ui.fileTypeComboBox->clear();

    QFileInfo info(path);
    QString fileName;

    if(info.isFile())
    {
        fileName = info.fileName();
        info = QFileInfo(info.absolutePath());
    }

    if(!info.exists())
    {
        info = QFileInfo(QDir::homePath());
        fileName.clear();
    }

    if (m_dirModel->filePath(m_ui.dirListView->rootIndex()) != info.absolutePath())
    {
        m_dirModel->setRootPath(info.path());
        m_ui.dirListView->setRootIndex(m_dirModel->index(info.absolutePath()));
    }
    m_ui.dirListView->setCurrentIndex(m_dirModel->index(info.absoluteFilePath()));
    m_ui.lookInComboBox->setEditText(info.absolutePath());

    m_ui.fileNameLineEdit->setText(fileName);
    m_ui.addButton->setEnabled(!fileName.isEmpty());
    m_ui.playButton->setEnabled(false);
    m_ui.playButton->setVisible(m == FileDialog::PlayDirsFiles);


    switch (m)
    {
    case FileDialog::AddFile:
    case FileDialog::AddFiles:
    case FileDialog::AddDirsFiles:
    case FileDialog::PlayDirsFiles:
    {
        m_ui.fileListWidget->setVisible(true);
        m_ui.addButton->setText(tr("Add"));
        m_ui.fileTypeComboBox->clear();
        m_ui.fileTypeComboBox->addItems(mask);
        m_ui.fileTypeComboBox->setEnabled(true);
        on_fileTypeComboBox_activated(0);
        m_ui.dirListView->setSelectionMode(QAbstractItemView::SingleSelection);
        if(m == FileDialog::AddFile)
            m_ui.fileListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
        else
            m_ui.fileListWidget->setSelectionMode (QAbstractItemView::ExtendedSelection);
        break;
    }
    case FileDialog::AddDir:
    case FileDialog::AddDirs:
    {
        m_ui.fileListWidget->setVisible(false);
        m_ui.addButton->setText(tr("Add"));
        m_ui.fileTypeComboBox->clear();
        m_ui.fileTypeComboBox->addItem(tr("Directories"));
        m_ui.fileTypeComboBox->setEnabled(false);
        if(m == FileDialog::AddDir)
            m_ui.dirListView->setSelectionMode(QAbstractItemView::SingleSelection);
        else
            m_ui.dirListView->setSelectionMode (QAbstractItemView::ExtendedSelection);
        m_ui.addButton->setEnabled(!m_ui.dirListView->selectionModel()->selectedRows().isEmpty());
        break;
    }
    case FileDialog::SaveFile:
    {
        m_ui.fileListWidget->setVisible(false);
        m_ui.addButton->setText(tr("Save"));
        m_ui.fileTypeComboBox->clear();
        m_ui.fileTypeComboBox->addItems(mask);
        m_ui.fileTypeComboBox->setEnabled(true);
        on_fileTypeComboBox_activated(0);
        m_ui.dirListView->setSelectionMode(QAbstractItemView::SingleSelection);
        m_ui.fileListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
        break;
    }
    default:
        ;
    }
}

void TwoPanelFileDialogImpl::on_fileTypeComboBox_activated(int index)
{
    m_filters = qt_clean_filter_list(m_ui.fileTypeComboBox->itemText(index));

    m_ui.fileListWidget->clear();

    QModelIndexList indexes = m_ui.dirListView->selectionModel()->selectedRows(0);

    if(!indexes.isEmpty() && indexes.first().isValid())
        updateFileList(m_dirModel->filePath(indexes.first()));
}

void TwoPanelFileDialogImpl::updateFileList(const QString &path)
{
    m_ui.fileListWidget->clear();
    QDir dir(path);
    dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    dir.setSorting(QDir::Name);

    for(const QFileInfo &info : dir.entryInfoList(m_filters))
    {
        QListWidgetItem *item = new QListWidgetItem(info.fileName());
        item->setIcon(m_dirModel->iconProvider()->icon(info));
        item->setData(Qt::UserRole, info.absoluteFilePath());
        m_ui.fileListWidget->addItem(item);
    }
}

void TwoPanelFileDialogImpl::hideEvent (QHideEvent *event)
{
    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    settings.setValue("TwoPanelFileDialog/geometry", saveGeometry());
    settings.setValue("TwoPanelFileDialog/history", m_history);
    QWidget::hideEvent(event);
}