traverso-commit
[Top][All Lists]
Advanced

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

[Traverso-commit] traverso/src core/AudioClip.cpp core/Utils.cpp ...


From: Remon Sijrier
Subject: [Traverso-commit] traverso/src core/AudioClip.cpp core/Utils.cpp ...
Date: Wed, 25 Apr 2007 15:58:50 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Remon Sijrier <r_sijrier>       07/04/25 15:58:50

Modified files:
        src/core       : AudioClip.cpp Utils.cpp Utils.h 
        src/traverso   : Interface.cpp 
        src/traverso/songcanvas: AudioClipView.cpp ClipsViewPort.cpp 
                                 ClipsViewPort.h 
        src/traverso/ui: ResourcesWidget.ui 
        src/traverso/widgets: ResourcesWidget.cpp ResourcesWidget.h 

Log message:
        * Some more work on the resource bin, doesn't work correctly though atm.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.cpp?cvsroot=traverso&r1=1.78&r2=1.79
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Utils.cpp?cvsroot=traverso&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Utils.h?cvsroot=traverso&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/Interface.cpp?cvsroot=traverso&r1=1.68&r2=1.69
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/songcanvas/AudioClipView.cpp?cvsroot=traverso&r1=1.50&r2=1.51
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/songcanvas/ClipsViewPort.cpp?cvsroot=traverso&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/songcanvas/ClipsViewPort.h?cvsroot=traverso&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/ui/ResourcesWidget.ui?cvsroot=traverso&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/widgets/ResourcesWidget.cpp?cvsroot=traverso&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/widgets/ResourcesWidget.h?cvsroot=traverso&r1=1.1&r2=1.2

Patches:
Index: core/AudioClip.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.cpp,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -b -r1.78 -r1.79
--- core/AudioClip.cpp  23 Apr 2007 11:48:36 -0000      1.78
+++ core/AudioClip.cpp  25 Apr 2007 15:58:49 -0000      1.79
@@ -84,6 +84,10 @@
        m_readSourceId = e.attribute("source", "").toLongLong();
        m_name = e.attribute( "clipname", "" ) ;
        isMuted =  e.attribute( "mute", "" ).toInt();
+       m_length = e.attribute( "length", "0" ).toUInt();
+       sourceStartFrame = e.attribute( "sourcestart", "" ).toUInt();
+       sourceEndFrame = sourceStartFrame + m_length;
+       set_track_start_frame( e.attribute( "trackstart", "" ).toUInt());
        m_domNode = node.cloneNode();
        init();
 }
@@ -117,6 +121,7 @@
        QDomElement e = node.toElement();
 
        isTake = e.attribute( "take", "").toInt();
+       isMuted =  e.attribute( "mute", "" ).toInt();
        set_gain( e.attribute( "gain", "" ).toFloat() );
        m_normfactor =  e.attribute( "normfactor", "1.0" ).toFloat();
 
@@ -124,14 +129,6 @@
                m_song->get_audioclip_manager()->select_clip(this);
        }
        
-       m_readSourceId = e.attribute("source", "").toLongLong();
-       isMuted =  e.attribute( "mute", "" ).toInt();
-
-       sourceStartFrame = e.attribute( "sourcestart", "" ).toUInt();
-       m_length = e.attribute( "length", "0" ).toUInt();
-       sourceEndFrame = sourceStartFrame + m_length;
-       set_track_start_frame( e.attribute( "trackstart", "" ).toUInt());
-
        QDomElement curvesNode = node.firstChildElement("Curves");
        if (!curvesNode.isNull()) {
                QDomElement fadeInNode = curvesNode.firstChildElement("FadeIn");

Index: core/Utils.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Utils.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- core/Utils.cpp      23 Apr 2007 11:52:24 -0000      1.7
+++ core/Utils.cpp      25 Apr 2007 15:58:49 -0000      1.8
@@ -58,6 +58,17 @@
        return QString().sprintf("%02d:%02d:%02d", hours, mins, secs);
 }
 
+QString frame_to_ms(double nframes, int rate)
+{
+       long unsigned int remainder;
+       int hours, mins, secs;
+
+       mins = (int) (nframes / ( 60 * rate ));
+       remainder = nframes - (mins * 60 * rate);
+       secs = (int) (remainder / rate);
+       return QString().sprintf("%02d:%02d", mins, secs);
+}
+
 
 nframes_t smpte_to_frame( QString str, int rate )
 {

Index: core/Utils.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/Utils.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- core/Utils.h        23 Apr 2007 11:52:24 -0000      1.8
+++ core/Utils.h        25 Apr 2007 15:58:49 -0000      1.9
@@ -32,6 +32,7 @@
 
 QString frame_to_smpte(nframes_t nframes, int rate);
 QString frame_to_hms(double nframes, int rate);
+QString frame_to_ms(double nframes, int rate);
 nframes_t smpte_to_frame(QString str, int rate);
 QString coefficient_to_dbstring(float coeff);
 QDateTime extract_date_time(qint64 id);

Index: traverso/Interface.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/Interface.cpp,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -b -r1.68 -r1.69
--- traverso/Interface.cpp      24 Apr 2007 23:57:10 -0000      1.68
+++ traverso/Interface.cpp      25 Apr 2007 15:58:49 -0000      1.69
@@ -120,7 +120,7 @@
        addDockWidget(Qt::RightDockWidgetArea, historyDW);
        
        // AudioSources View
-       AudioSourcesDW = new QDockWidget(tr("Audio Bin"), this);
+       AudioSourcesDW = new QDockWidget(tr("Resources Bin"), this);
        AudioSourcesDW->setObjectName("AudioSourcesDockWidget");
        audiosourcesview = new ResourcesWidget(AudioSourcesDW);
        audiosourcesview->setFocusPolicy(Qt::NoFocus);

Index: traverso/songcanvas/AudioClipView.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/songcanvas/AudioClipView.cpp,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- traverso/songcanvas/AudioClipView.cpp       23 Apr 2007 17:56:53 -0000      
1.50
+++ traverso/songcanvas/AudioClipView.cpp       25 Apr 2007 15:58:50 -0000      
1.51
@@ -249,10 +249,12 @@
        for (int chan=0; chan < channels; chan++) {
                memset(buffers[chan], 0, buffersize * sizeof(unsigned char));
                
+               nframes_t clipstartoffset = m_clip->get_source_start_frame();
+               
                Peak* peak = m_clip->get_peak_for_channel(chan);
                int availpeaks = peak->calculate_peaks( buffers[chan],
                                                        microView ? 
m_song->get_hzoom() : m_song->get_hzoom() + 1,
-                                                       (xstart * 
m_sv->scalefactor) + m_clip->get_source_start_frame(),
+                                                       (xstart * 
m_sv->scalefactor) + clipstartoffset,
                                                        microView ? 
peakdatacount : peakdatacount / 2);
                
                if (peakdatacount != availpeaks) {

Index: traverso/songcanvas/ClipsViewPort.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/songcanvas/ClipsViewPort.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- traverso/songcanvas/ClipsViewPort.cpp       12 Apr 2007 12:48:17 -0000      
1.13
+++ traverso/songcanvas/ClipsViewPort.cpp       25 Apr 2007 15:58:50 -0000      
1.14
@@ -17,7 +17,7 @@
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
 
-$Id: ClipsViewPort.cpp,v 1.13 2007/04/12 12:48:17 r_sijrier Exp $
+$Id: ClipsViewPort.cpp,v 1.14 2007/04/25 15:58:50 r_sijrier Exp $
 */
 
 #include "ClipsViewPort.h"
@@ -72,13 +72,31 @@
 //     printf("ClipsViewPort::paintEvent\n");
        QGraphicsView::paintEvent(e);
 }
-
+#include <QModelIndex>
 
 void ClipsViewPort::dragEnterEvent( QDragEnterEvent * event )
 {
-       bool accepted = true;
        m_imports.clear();
+       m_resourcesImport.clear();
+       
+       // let's see if the D&D was from the resources bin.
+       if 
(event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) {
+               QByteArray encodedData = 
event->mimeData()->data("application/x-qabstractitemmodeldatalist");
+               QDataStream stream(&encodedData, QIODevice::ReadOnly);
+               int r, c;
+               QMap<int, QVariant> v;
+               
+               while (!stream.atEnd()) {
+                       stream >> r >> c >> v;
+                       qint64 id = v.value(Qt::UserRole).toLongLong();
+                       if (!id) {
+                               continue;
+                       }
+                       m_resourcesImport.append(id);
+               }
+       }
        
+       // and who knows, it could have been a D&D drop from a filemanager...
        if (event->mimeData()->hasUrls()) {
 
                foreach(QUrl url, event->mimeData()->urls()) {
@@ -91,24 +109,27 @@
                        Import* import = new Import(fileName);
                        m_imports.append(import);
                        
+                       // If a readsource fails to init, the D&D should be
+                       // marked as failed, cleanup allready created imports,
+                       // and clear the import list.
                        if (import->create_readsource() == -1) {
                                foreach(Import* import, m_imports) {
                                        delete import;
                                }
                                m_imports.clear();
-                               accepted = false;
                                break;
                        }
                }
        }
        
-       if (accepted) {
+       if (m_imports.size() || m_resourcesImport.size()) {
                event->acceptProposedAction();
        }
 }
 
 void ClipsViewPort::dropEvent(QDropEvent* event )
 {
+       PENTER;
        Q_UNUSED(event)
        
        if (!importTrack) {
@@ -116,7 +137,19 @@
        }
 
        CommandGroup* group = new CommandGroup(m_sw->get_song(), 
-                      tr("Import %n audiofile(s)", "", m_imports.size()), 
true);
+                      tr("Import %n audiofile(s)", "", m_imports.size() + 
m_resourcesImport.size()), true);
+       
+       
+       foreach(qint64 id, m_resourcesImport) {
+               AudioClip* clip = resources_manager()->get_clip(id);
+               if (clip) {
+                       clip->set_song(m_sw->get_song());
+                       clip->set_track(importTrack);
+//                     clip->set_state(clip->get_dom_node());
+                       clip->set_track_start_frame(0);
+                       group->add_command(importTrack->add_clip(clip));
+               }
+       }
        
        foreach(Import* import, m_imports) {
                import->set_track(importTrack);

Index: traverso/songcanvas/ClipsViewPort.h
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/songcanvas/ClipsViewPort.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- traverso/songcanvas/ClipsViewPort.h 22 Mar 2007 20:54:23 -0000      1.9
+++ traverso/songcanvas/ClipsViewPort.h 25 Apr 2007 15:58:50 -0000      1.10
@@ -50,6 +50,7 @@
 private:
        SongWidget*     m_sw;
        QList<Import*>  m_imports;
+       QList<qint64 >  m_resourcesImport;
        Track*          importTrack;
 };
 

Index: traverso/ui/ResourcesWidget.ui
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/ui/ResourcesWidget.ui,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- traverso/ui/ResourcesWidget.ui      24 Apr 2007 23:57:10 -0000      1.1
+++ traverso/ui/ResourcesWidget.ui      25 Apr 2007 15:58:50 -0000      1.2
@@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>151</width>
-    <height>258</height>
+    <height>289</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -28,7 +28,15 @@
       <number>6</number>
      </property>
      <item>
-      <widget class="QComboBox" name="comboBox_2" >
+      <widget class="QComboBox" name="viewComboBox" >
+       <property name="sizePolicy" >
+        <sizepolicy>
+         <hsizetype>5</hsizetype>
+         <vsizetype>0</vsizetype>
+         <horstretch>2</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
        <item>
         <property name="text" >
          <string>Audio</string>
@@ -47,7 +55,7 @@
       </widget>
      </item>
      <item>
-      <widget class="QComboBox" name="comboBox" />
+      <widget class="QComboBox" name="songComboBox" />
      </item>
      <item>
       <spacer>
@@ -76,7 +84,12 @@
       <widget class="QTreeWidget" name="audioFileTreeWidget" >
        <column>
         <property name="text" >
-         <string>AudioFiles</string>
+         <string>Audio Name</string>
+        </property>
+       </column>
+       <column>
+        <property name="text" >
+         <string>Length</string>
         </property>
        </column>
       </widget>
@@ -85,7 +98,22 @@
       <widget class="QTreeWidget" name="clipTreeWidget" >
        <column>
         <property name="text" >
-         <string>Clips</string>
+         <string>Clip Name</string>
+        </property>
+       </column>
+       <column>
+        <property name="text" >
+         <string>Start</string>
+        </property>
+       </column>
+       <column>
+        <property name="text" >
+         <string>End</string>
+        </property>
+       </column>
+       <column>
+        <property name="text" >
+         <string>Length</string>
         </property>
        </column>
       </widget>
@@ -93,6 +121,24 @@
     </layout>
    </item>
   </layout>
+  <widget class="QWidget" name="" >
+   <property name="geometry" >
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>2</width>
+     <height>2</height>
+    </rect>
+   </property>
+   <layout class="QVBoxLayout" >
+    <property name="margin" >
+     <number>0</number>
+    </property>
+    <property name="spacing" >
+     <number>6</number>
+    </property>
+   </layout>
+  </widget>
  </widget>
  <resources/>
  <connections/>

Index: traverso/widgets/ResourcesWidget.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/widgets/ResourcesWidget.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- traverso/widgets/ResourcesWidget.cpp        24 Apr 2007 23:57:10 -0000      
1.1
+++ traverso/widgets/ResourcesWidget.cpp        25 Apr 2007 15:58:50 -0000      
1.2
@@ -23,11 +23,15 @@
 
 #include <ProjectManager.h>
 #include <Project.h>
+#include <Song.h>
 #include <ResourcesManager.h>
 #include <AudioSource.h>
 #include <ReadSource.h>
 #include <AudioClip.h>
 #include <Utils.h>
+#include <Themer.h>
+
+#include <QHeaderView>
 
 
 ResourcesWidget::ResourcesWidget(QWidget * parent)
@@ -36,8 +40,37 @@
        setupUi(this);
 /*     audioFileTreeWidget->hide();
        clipTreeWidget->show();*/
+       QPalette palette;
+       palette.setColor(QPalette::AlternateBase, 
themer()->get_color("Track:background"));
+       clipTreeWidget->setPalette(palette);
+       clipTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
+       clipTreeWidget->setAlternatingRowColors(true);
+       clipTreeWidget->setDragEnabled(true);
+       clipTreeWidget->setDropIndicatorShown(true);
+       clipTreeWidget->setIndentation(12);
+       clipTreeWidget->header()->setResizeMode(0, 
QHeaderView::ResizeToContents);
+       clipTreeWidget->header()->setResizeMode(1, 
QHeaderView::ResizeToContents);
+       clipTreeWidget->header()->setResizeMode(2, 
QHeaderView::ResizeToContents);
+       clipTreeWidget->header()->setResizeMode(3, 
QHeaderView::ResizeToContents);
+       clipTreeWidget->hide();
+       
+       audioFileTreeWidget->setPalette(palette);
+       
audioFileTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
+       audioFileTreeWidget->setAlternatingRowColors(true);
+       audioFileTreeWidget->setDragEnabled(true);
+       audioFileTreeWidget->setDropIndicatorShown(true);
+       audioFileTreeWidget->setIndentation(12);
+       audioFileTreeWidget->header()->setResizeMode(0, 
QHeaderView::ResizeToContents);
+       audioFileTreeWidget->header()->setResizeMode(1, 
QHeaderView::ResizeToContents);
+       
+       viewComboBox->setFocusPolicy(Qt::NoFocus);
+       songComboBox->setFocusPolicy(Qt::NoFocus);
+       clipTreeWidget->setFocusPolicy(Qt::NoFocus);
+       audioFileTreeWidget->setFocusPolicy(Qt::NoFocus);
+
        
-       set_project(pm().get_project());
+       connect(viewComboBox, SIGNAL(currentIndexChanged(int)), this, 
SLOT(view_combo_box_index_changed(int)));
+       connect(songComboBox, SIGNAL(currentIndexChanged(int)), this, 
SLOT(song_combo_box_index_changed(int)));
        connect(&pm(), SIGNAL(projectLoaded(Project*)), this, 
SLOT(set_project(Project*)));
 }
 
@@ -47,40 +80,84 @@
 
 void ResourcesWidget::set_project(Project * project)
 {
-/*     audioFileTreeWidget->clear();
-       clipTreeWidget->clear();*/
+       audioFileTreeWidget->clear();
+       clipTreeWidget->clear();
+       songComboBox->clear();
        
        m_project = project;
        
        if (!m_project) {
+               songComboBox->setEnabled(false);
                return;
        }
        
+       songComboBox->setEnabled(true);
+       
        connect(m_project->get_audiosource_manager(), SIGNAL(sourceAdded()), 
this, SLOT(update_tree_widgets()));
+       connect(m_project, SIGNAL(songAdded(Song*)), this, 
SLOT(song_added(Song*)));
+       connect(m_project, SIGNAL(songRemoved(Song*)), this, 
SLOT(song_removed(Song*)));
+       
        update_tree_widgets();
 }
 
 void ResourcesWidget::update_tree_widgets()
 {
-       ResourcesManager* manager = resources_manager();
-       if (! manager) {
-               return;
-       }
-       
-       foreach(ReadSource* rs, manager->get_all_audio_sources()) {
+       foreach(ReadSource* rs, 
m_project->get_audiosource_manager()->get_all_audio_sources()) {
                QTreeWidgetItem* item = new 
QTreeWidgetItem(audioFileTreeWidget);
+               QString duration = frame_to_ms(rs->get_nframes(), 44100);
                item->setText(0, rs->get_name());
+               item->setText(1, duration);
                item->setData(0, Qt::UserRole, rs->get_id());
+               item->setToolTip(0, rs->get_name() + "   " + duration);
        }
        
        
-       foreach(AudioClip* clip, resources_manager()->get_all_clips()) {
+       foreach(AudioClip* clip, 
m_project->get_audiosource_manager()->get_all_clips()) {
                QTreeWidgetItem* item = new QTreeWidgetItem(clipTreeWidget);
                item->setText(0, clip->get_name());
+               QString start = frame_to_ms(clip->get_source_start_frame(), 
clip->get_rate());
+               QString end = frame_to_ms(clip->get_source_end_frame(), 
clip->get_rate());
+               item->setText(1, start);
+               item->setText(2, end);
+               item->setText(3, frame_to_ms(clip->get_length(), 
clip->get_rate()));
                item->setData(0, Qt::UserRole, clip->get_id());
+               item->setToolTip(0, clip->get_name() + "   " + start + " - " + 
end);
        }
 
        clipTreeWidget->sortItems(0, Qt::AscendingOrder);
        audioFileTreeWidget->sortItems(0, Qt::AscendingOrder);
 }
 
+void ResourcesWidget::view_combo_box_index_changed(int index)
+{
+       if (index == 0) {
+               audioFileTreeWidget->show();
+               clipTreeWidget->hide();
+       } else if (index == 1) {
+               audioFileTreeWidget->hide();
+               clipTreeWidget->show();
+       } else {
+               audioFileTreeWidget->show();
+               clipTreeWidget->show();
+       }
+               
+}
+
+void ResourcesWidget::song_combo_box_index_changed(int index)
+{
+       update_tree_widgets();
+}
+
+void ResourcesWidget::song_added(Song * song)
+{
+       songComboBox->addItem("Song " + 
QString::number(m_project->get_song_index(song->get_id())), song->get_id());
+       update_tree_widgets();
+}
+
+void ResourcesWidget::song_removed(Song * song)
+{
+       int index = songComboBox->findData(song->get_id());
+       songComboBox->removeItem(index);
+       update_tree_widgets();
+}
+

Index: traverso/widgets/ResourcesWidget.h
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/widgets/ResourcesWidget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- traverso/widgets/ResourcesWidget.h  24 Apr 2007 23:57:10 -0000      1.1
+++ traverso/widgets/ResourcesWidget.h  25 Apr 2007 15:58:50 -0000      1.2
@@ -26,6 +26,7 @@
 #include "ui_ResourcesWidget.h"
 
 class Project;
+class Song;
 
 class ResourcesWidget : public QWidget, protected Ui::ResourcesWidget
 {
@@ -44,6 +45,10 @@
 private slots:
        void set_project(Project* project);
        void update_tree_widgets();
+       void view_combo_box_index_changed(int index);
+       void song_combo_box_index_changed(int index);
+       void song_added(Song* song);
+       void song_removed(Song* song);
 };
 
 #endif




reply via email to

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