traverso-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Traverso-commit] traverso/src core/CMakeLists.txt core/core.pro ...


From: Nicola Doebelin
Subject: [Traverso-commit] traverso/src core/CMakeLists.txt core/core.pro ...
Date: Thu, 22 May 2008 11:28:35 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Nicola Doebelin <n_doebelin>    08/05/22 11:28:35

Modified files:
        src/core       : CMakeLists.txt core.pro ReadSource.h 
        src/traverso/dialogs/project: NewProjectDialog.cpp 
                                      NewProjectDialog.h 
        src/traverso/ui: NewProjectDialog.ui 
Added files:
        src/core       : AudioFileCopyConvert.cpp AudioFileCopyConvert.h 

Log message:
        * new implementation of "copy audio files to project dir" in the 
newProject dialog. This is the first working vesion, all file formats are 
expanded to wave, and a few glitches are likely to occur.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/CMakeLists.txt?cvsroot=traverso&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/core.pro?cvsroot=traverso&r1=1.47&r2=1.48
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ReadSource.h?cvsroot=traverso&r1=1.47&r2=1.48
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioFileCopyConvert.cpp?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioFileCopyConvert.h?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/dialogs/project/NewProjectDialog.cpp?cvsroot=traverso&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/dialogs/project/NewProjectDialog.h?cvsroot=traverso&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/ui/NewProjectDialog.ui?cvsroot=traverso&r1=1.6&r2=1.7

Patches:
Index: core/CMakeLists.txt
===================================================================
RCS file: /sources/traverso/traverso/src/core/CMakeLists.txt,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- core/CMakeLists.txt 21 Feb 2008 20:00:48 -0000      1.11
+++ core/CMakeLists.txt 22 May 2008 11:28:34 -0000      1.12
@@ -48,6 +48,7 @@
 Marker.cpp
 Themer.cpp
 AudioFileMerger.cpp
+AudioFileCopyConvert.cpp
 ProjectConverter.cpp
 )
 
@@ -56,6 +57,7 @@
 AudioClip.h
 AudioClipManager.h
 AudioFileMerger.h
+AudioFileCopyConvert.h
 Config.h
 ContextPointer.h
 Curve.h

Index: core/core.pro
===================================================================
RCS file: /sources/traverso/traverso/src/core/core.pro,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -b -r1.47 -r1.48
--- core/core.pro       19 Nov 2007 11:18:53 -0000      1.47
+++ core/core.pro       22 May 2008 11:28:34 -0000      1.48
@@ -57,6 +57,7 @@
        Marker.cpp \
        Themer.cpp \
        AudioFileMerger.cpp \
+       AudioFileCopyConvert.cpp \
        ProjectConverter.cpp
 HEADERS = precompile.h \
        ../common/Utils.h \
@@ -102,6 +103,7 @@
        Marker.h \
        Themer.h \
        AudioFileMerger.h \
+       AudioFileCopyConvert.h \
        ProjectConverter.h
 macx{
     QMAKE_LIBDIR += /usr/local/qt/lib

Index: core/ReadSource.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/ReadSource.h,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -b -r1.47 -r1.48
--- core/ReadSource.h   21 Feb 2008 20:00:48 -0000      1.47
+++ core/ReadSource.h   22 May 2008 11:28:34 -0000      1.48
@@ -72,6 +72,7 @@
        nframes_t get_nframes() const;
        int get_file_rate() const;
        int get_output_rate() const {return m_outputRate;}
+       int get_channel_cound() const {return m_channelCount;}
        const TimeRef& get_length() const {return m_length;}
        
        void sync(DecodeBuffer* buffer);

Index: traverso/dialogs/project/NewProjectDialog.cpp
===================================================================
RCS file: 
/sources/traverso/traverso/src/traverso/dialogs/project/NewProjectDialog.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- traverso/dialogs/project/NewProjectDialog.cpp       21 May 2008 20:07:19 
-0000      1.8
+++ traverso/dialogs/project/NewProjectDialog.cpp       22 May 2008 11:28:35 
-0000      1.9
@@ -35,7 +35,8 @@
 #include <QList>
 #include <QFileInfo>
 #include <QFile>
-#include <QRadioButton>
+#include <QCheckBox>
+#include <QProgressDialog>
 
 #include <Config.h>
 #include <Information.h>
@@ -46,6 +47,8 @@
 #include <Utils.h>
 #include <CommandGroup.h>
 #include "Import.h"
+#include "AudioFileCopyConvert.h"
+#include "ReadSource.h"
 
 
 // Always put me below _all_ includes, this is needed
@@ -63,9 +66,15 @@
 
        buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
 
+       m_converter = new AudioFileCopyConvert();
+       m_progressDialog = new QProgressDialog(this);
+
        connect(useTemplateCheckBox, SIGNAL(stateChanged (int)), this, 
SLOT(use_template_checkbox_state_changed(int)));
        connect(pushButtonAddFiles, SIGNAL(clicked()), this, SLOT(add_files()));
        connect(pushButtonRemoveFiles, SIGNAL(clicked()), this, 
SLOT(remove_files()));
+       connect(m_converter, SIGNAL(taskFinished(QString, int)), this, 
SLOT(load_file(QString, int)));
+       connect(m_converter, SIGNAL(taskStarted(QString)), this, 
SLOT(show_progress(QString)));
+       connect(m_converter, SIGNAL(progress(int)), m_progressDialog, 
SLOT(setValue(int)));
 }
 
 NewProjectDialog::~ NewProjectDialog( )
@@ -146,10 +155,12 @@
        
        pm().load_project(title);
 
-       if (loadFiles)
-       {
-               move_files(radioButtonCopy->isChecked() ? 1 : 0);
-               load_files();
+       if (loadFiles) {
+               if (checkBoxCopy->isChecked()) {
+                       copy_files();
+               } else {
+                       load_all_files();
+               }
        }
 
        hide();
@@ -207,13 +218,9 @@
        }
 }
 
-void NewProjectDialog::move_files(int mode)
+void NewProjectDialog::copy_files()
 {
-       // load from original location
-       if (mode == 0)
-       {
-               return;
-       }
+       m_progressDialog->show();
 
        QList<QFileInfo> list;
        for(int n = 0; n < treeWidgetFiles->topLevelItemCount(); ++n) {
@@ -232,50 +239,54 @@
                // TODO: progress dialog for copying files
                // TODO: offer file format conversion while copying
 
-               QFile f(list.at(n).absoluteFilePath());
-               if (f.copy(fn))
-               {
+               ReadSource* readsource = new 
ReadSource(list.at(n).absolutePath() + "/", list.at(n).fileName());
+               readsource->init();
+               m_converter->enqueue_task(readsource, destination, 
list.at(n).fileName(), n);
+
                        // copy was successful, thus update the file path
                        QTreeWidgetItem* item = 
treeWidgetFiles->topLevelItem(n);
                        item->setData(0, Qt::ToolTipRole, fn);
                }
-       }
 }
 
-void NewProjectDialog::load_files()
+void NewProjectDialog::load_all_files()
 {
-               Sheet* sheet = pm().get_project()->get_current_sheet();
-
-               if (!sheet)
-               {
-                       return;
-               }
-
                int i = 0;
 
-               CommandGroup* group = new CommandGroup(sheet, tr("Import %n 
audiofile(s)", "",
-                       treeWidgetFiles->topLevelItemCount()), false);
-
-
                while(treeWidgetFiles->topLevelItemCount()) {
                        QTreeWidgetItem* item = 
treeWidgetFiles->takeTopLevelItem(0);
                        QString f = item->data(0, Qt::ToolTipRole).toString();
                        delete item;
 
-                       if (i < sheet->get_numtracks())
-                       {
-                               Import* import = new Import(f);
-                               
import->set_track(sheet->get_track_for_index(i));
-                               import->set_position((TimeRef)0.0);
-                               if (import->create_readsource() != -1)
-                               {
-                                       group->add_command(import);
+                       load_file(f, i);
+                       ++i;
                                }
+}
+
+void NewProjectDialog::load_file(QString name, int i)
+{
+       Sheet* sheet = pm().get_project()->get_current_sheet();
+
+       if (!sheet) {
+               return;
                        }
-                       ++i;
+
+       if (i >= sheet->get_numtracks()) {
+               return;
                }
 
-               Command::process_command(group);
+       Import* import = new Import(name);
+       import->set_track(sheet->get_track_for_index(i));
+       import->set_position((TimeRef)0.0);
+       if (import->create_readsource() != -1) {
+               Command::process_command(import);
+       }
+}
+
+void NewProjectDialog::show_progress(QString name)
+{
+       m_progressDialog->setLabelText(name);
+       m_progressDialog->show();
 }
 
 //eof

Index: traverso/dialogs/project/NewProjectDialog.h
===================================================================
RCS file: 
/sources/traverso/traverso/src/traverso/dialogs/project/NewProjectDialog.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- traverso/dialogs/project/NewProjectDialog.h 21 May 2008 19:11:26 -0000      
1.3
+++ traverso/dialogs/project/NewProjectDialog.h 22 May 2008 11:28:35 -0000      
1.4
@@ -25,6 +25,9 @@
 #include "ui_NewProjectDialog.h"
 #include <QDialog>
 
+class AudioFileCopyConvert;
+class QProgressDialog;
+
 class NewProjectDialog : public QDialog, protected Ui::NewProjectDialog
 {
        Q_OBJECT
@@ -34,8 +37,11 @@
        ~NewProjectDialog();
 
 private:
-       void load_files();
-       void move_files(int);
+       AudioFileCopyConvert* m_converter;
+       QProgressDialog* m_progressDialog;
+
+       void load_all_files();
+       void copy_files();
 
 private slots:
        void accept();
@@ -43,6 +49,11 @@
        void update_template_combobox();
        void add_files();
        void remove_files();
+       void load_file(QString, int);
+       void show_progress(QString);
+
+signals:
+       void loadFile(QString, int);
 };
 
 #endif

Index: traverso/ui/NewProjectDialog.ui
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/ui/NewProjectDialog.ui,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- traverso/ui/NewProjectDialog.ui     21 May 2008 20:07:20 -0000      1.6
+++ traverso/ui/NewProjectDialog.ui     22 May 2008 11:28:35 -0000      1.7
@@ -210,19 +210,9 @@
         </widget>
        </item>
        <item>
-        <widget class="QRadioButton" name="radioButtonLeave" >
+        <widget class="QCheckBox" name="checkBoxCopy" >
          <property name="text" >
-          <string>load files from original location</string>
-         </property>
-         <property name="checked" >
-          <bool>true</bool>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QRadioButton" name="radioButtonCopy" >
-         <property name="text" >
-          <string>copy files to project directory</string>
+          <string>Copy files to project directory</string>
          </property>
         </widget>
        </item>

Index: core/AudioFileCopyConvert.cpp
===================================================================
RCS file: core/AudioFileCopyConvert.cpp
diff -N core/AudioFileCopyConvert.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ core/AudioFileCopyConvert.cpp       22 May 2008 11:28:34 -0000      1.1
@@ -0,0 +1,174 @@
+/*
+Copyright (C) 2007 Remon Sijrier 
+
+This file is part of Traverso
+
+Traverso 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 St, Fifth Floor, Boston, MA  02110-1301  USA.
+
+*/
+
+#include "AudioFileCopyConvert.h"
+#include <QFile>
+#include <QMutexLocker>
+#include <QFileInfo>
+
+#include "Export.h"
+#include "AbstractAudioReader.h"
+#include "ReadSource.h"
+#include "WriteSource.h"
+#include "Peak.h"
+#include "defines.h"
+
+AudioFileCopyConvert::AudioFileCopyConvert()
+{
+       m_stopProcessing = false;
+       moveToThread(this);
+       start();
+       connect(this, SIGNAL(dequeueTask()), this, SLOT(dequeue_tasks()), 
Qt::QueuedConnection);
+}
+
+void AudioFileCopyConvert::enqueue_task(ReadSource * source, const QString& 
dir, const QString & outfilename, int tracknumber)
+{
+       QFileInfo fi(outfilename);
+
+       CopyTask task;
+       task.readsource = source;
+       task.outFileName = fi.completeBaseName();
+       task.extension = fi.suffix();
+       task.tracknumber = tracknumber;
+       task.dir = dir;
+       
+       m_mutex.lock();
+       m_tasks.enqueue(task);
+       m_mutex.unlock();
+       
+       emit dequeueTask();
+}
+
+void AudioFileCopyConvert::dequeue_tasks()
+{
+       m_mutex.lock();
+       if (m_tasks.size()) {
+               CopyTask task = m_tasks.dequeue();
+               m_mutex.unlock();
+               process_task(task);
+               return;
+       }
+       m_mutex.unlock();
+}
+
+void AudioFileCopyConvert::process_task(CopyTask task)
+{
+       QString name = task.readsource->get_name();
+       int length = name.length();
+       emit taskStarted(name.left(length-28));
+       uint buffersize = 16384;
+       DecodeBuffer decodebuffer;
+       
+       ExportSpecification* spec = new ExportSpecification();
+       spec->startLocation = TimeRef();
+       spec->endLocation = task.readsource->get_length();
+       spec->totalTime = spec->endLocation;
+       spec->pos = TimeRef();
+       spec->isRecording = false;
+       
+       spec->exportdir = task.dir;
+       spec->writerType = "sndfile";
+       spec->extraFormat["filetype"] = "wav";
+       spec->data_width = 1;   // 1 means float
+       spec->channels = task.readsource->get_channel_count();
+       spec->sample_rate = task.readsource->get_rate();
+       spec->blocksize = buffersize;
+       spec->name = task.outFileName;
+       spec->dataF = new audio_sample_t[buffersize * 2];
+       
+       WriteSource* writesource = new WriteSource(spec);
+       if (writesource->prepare_export() == -1) {
+               delete writesource;
+               delete [] spec->dataF;
+               delete spec;
+               return;
+       }
+       // Enable on the fly generation of peak data to speedup conversion 
+       // (no need to re-read all the audio files to generate peaks)
+       writesource->set_process_peaks(true);
+       
+       int oldprogress = 0;
+       do {
+               // if the user asked to stop processing, jump out of this 
+               // loop, and cleanup any resources in use.
+               if (m_stopProcessing) {
+                       goto out;
+               }
+                       
+               nframes_t diff = (spec->endLocation - 
spec->pos).to_frame(task.readsource->get_rate());
+               nframes_t this_nframes = std::min(diff, buffersize);
+               nframes_t nframes = this_nframes;
+               
+               memset (spec->dataF, 0, sizeof (spec->dataF[0]) * nframes * 
spec->channels);
+               
+               task.readsource->file_read(&decodebuffer, spec->pos, nframes);
+                       
+               for (uint x = 0; x < nframes; ++x) {
+                       for (int y = 0; y < spec->channels; ++y) {
+                               spec->dataF[y + x*spec->channels] = 
decodebuffer.destination[y][x];
+                       }
+               }
+               
+               // due the fact peak generating does _not_ happen in 
writesource->process
+               // but in a function used by DiskIO, we have to hack the peak 
processing 
+               // in here.
+               for (int y = 0; y < spec->channels; ++y) {
+                       writesource->get_peak()->process(y, 
decodebuffer.destination[y], nframes);
+               }
+               
+               // Process the data, and write to disk
+               writesource->process(buffersize);
+               
+               spec->pos.add_frames(nframes, task.readsource->get_rate());
+               
+               int currentprogress = int(double(spec->pos.universal_frame()) / 
double(spec->totalTime.universal_frame()) * 100);
+               if (currentprogress > oldprogress) {
+                       oldprogress = currentprogress;
+                       emit progress(currentprogress);
+               }
+                       
+       } while (spec->pos != spec->totalTime);
+               
+       
+       out:
+       writesource->finish_export();
+       delete writesource;
+       delete [] spec->dataF;
+       delete spec;
+       
+       //  The user asked to stop processing, exit the event loop
+       // and signal we're done.
+       if (m_stopProcessing) {
+               exit(0);
+               wait(1000);
+               m_tasks.clear();
+               emit processingStopped();
+               return;
+       }
+       
+       emit taskFinished(task.dir + "/" + task.outFileName + ".wav", 
task.tracknumber);
+}
+
+void AudioFileCopyConvert::stop_merging()
+{
+       m_stopProcessing = true;
+}
+

Index: core/AudioFileCopyConvert.h
===================================================================
RCS file: core/AudioFileCopyConvert.h
diff -N core/AudioFileCopyConvert.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ core/AudioFileCopyConvert.h 22 May 2008 11:28:34 -0000      1.1
@@ -0,0 +1,70 @@
+/*
+Copyright (C) 2007 Remon Sijrier 
+
+This file is part of Traverso
+
+Traverso 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 St, Fifth Floor, Boston, MA  02110-1301  USA.
+
+*/
+
+#ifndef AUDIO_FILE_COPY_CONVERT_H
+#define AUDIO_FILE_COPY_CONVERT_H
+
+#include <QThread>
+#include <QQueue>
+#include <QMutex>
+
+class ReadSource;
+
+class AudioFileCopyConvert : public QThread
+{
+       Q_OBJECT
+public:
+       AudioFileCopyConvert();
+       void run() {
+               exec();
+       }
+       
+       void enqueue_task(ReadSource* source, const QString& dir, const 
QString& outfilename, int tracknumber);
+       void stop_merging();
+
+               
+private slots:
+       void dequeue_tasks();
+       
+private:
+       struct CopyTask {
+               QString outFileName;
+               QString dir;
+               QString extension;
+               int tracknumber;
+               ReadSource* readsource;
+       };
+       
+       QQueue<CopyTask> m_tasks;
+       QMutex m_mutex;
+       bool m_stopProcessing;
+       
+       void process_task(CopyTask task);
+       
+signals:
+       void dequeueTask();
+       void progress(int);
+       void taskStarted(QString);
+       void taskFinished(QString, int);
+       void processingStopped();
+};
+
+#endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]