[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Traverso-commit] traverso/src commands/RemoveClip.cpp commands/R...
From: |
Remon Sijrier |
Subject: |
[Traverso-commit] traverso/src commands/RemoveClip.cpp commands/R... |
Date: |
Sat, 05 May 2007 20:43:58 +0000 |
CVSROOT: /sources/traverso
Module name: traverso
Changes by: Remon Sijrier <r_sijrier> 07/05/05 20:43:58
Modified files:
src/commands : RemoveClip.cpp RemoveClip.h
src/core : AudioClip.cpp AudioClip.h AudioClipManager.cpp
ReadSource.cpp ReadSource.h
ResourcesManager.cpp ResourcesManager.h
src/traverso/widgets: ResourcesWidget.cpp ResourcesWidget.h
Log message:
* Resources work, not finished, but commited to keep cvs compiling.
Breaks recording, working on it
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/commands/RemoveClip.cpp?cvsroot=traverso&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/traverso/src/commands/RemoveClip.h?cvsroot=traverso&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.cpp?cvsroot=traverso&r1=1.86&r2=1.87
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.h?cvsroot=traverso&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClipManager.cpp?cvsroot=traverso&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ReadSource.cpp?cvsroot=traverso&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ReadSource.h?cvsroot=traverso&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ResourcesManager.cpp?cvsroot=traverso&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ResourcesManager.h?cvsroot=traverso&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/widgets/ResourcesWidget.cpp?cvsroot=traverso&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/widgets/ResourcesWidget.h?cvsroot=traverso&r1=1.4&r2=1.5
Patches:
Index: commands/RemoveClip.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/commands/RemoveClip.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- commands/RemoveClip.cpp 30 Apr 2007 10:09:11 -0000 1.7
+++ commands/RemoveClip.cpp 5 May 2007 20:43:58 -0000 1.8
@@ -23,40 +23,71 @@
#include <AudioClip.h>
#include <Track.h>
+#include "ResourcesManager.h"
+#include "ProjectManager.h"
// Always put me below _all_ includes, this is needed
// in case we run with memory leak detection enabled!
#include "Debugger.h"
-RemoveClip::RemoveClip(AudioClip* clip)
+AddRemoveClip::AddRemoveClip(AudioClip* clip, int type)
: Command(clip, tr("Remove Clip"))
{
m_clip = clip;
m_track = m_clip->get_track();
+ m_type = type;
+ m_removeFromDataBase = false;
}
-int RemoveClip::prepare_actions()
+int AddRemoveClip::prepare_actions()
{
return 1;
}
-int RemoveClip::do_action()
+int AddRemoveClip::do_action()
{
PENTER;
+ if (m_type == REMOVE) {
Command::process_command(m_track->remove_clip(m_clip, false));
+ }
+
+ if (m_type == ADD) {
+ Command::process_command(m_track->add_clip(m_clip, false));
+ }
+
+ if (m_removeFromDataBase) {
+
resources_manager()->undo_remove_clip_from_database(m_clip->get_id());
+ }
+
return 1;
}
-int RemoveClip::undo_action()
+int AddRemoveClip::undo_action()
{
PENTER;
+ if (m_type == REMOVE) {
Command::process_command(m_track->add_clip(m_clip, false));
+ }
+
+ if (m_type == ADD) {
+ Command::process_command(m_track->remove_clip(m_clip, false));
+ }
+
+ if (m_removeFromDataBase) {
+
resources_manager()->remove_clip_from_database(m_clip->get_id());
+ }
+
return 1;
}
+void AddRemoveClip::remove_from_database_when_removed(bool remove)
+{
+ m_removeFromDataBase = remove;
+}
+
// eof
Index: commands/RemoveClip.h
===================================================================
RCS file: /sources/traverso/traverso/src/commands/RemoveClip.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- commands/RemoveClip.h 30 Apr 2007 10:09:11 -0000 1.3
+++ commands/RemoveClip.h 5 May 2007 20:43:58 -0000 1.4
@@ -27,17 +27,26 @@
class AudioClip;
class Track;
-class RemoveClip : public Command
+class AddRemoveClip : public Command
{
public :
- RemoveClip(AudioClip* clip);
- ~RemoveClip() {};
+ AddRemoveClip(AudioClip* clip, int type);
+ ~AddRemoveClip() {};
+
+ enum {
+ ADD,
+ REMOVE
+ };
int prepare_actions();
int do_action();
int undo_action();
+ void remove_from_database_when_removed(bool remove);
+
private :
+ int m_type;
+ bool m_removeFromDataBase;
AudioClip* m_clip;
Track* m_track;
};
Index: core/AudioClip.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.cpp,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -b -r1.86 -r1.87
--- core/AudioClip.cpp 3 May 2007 10:38:29 -0000 1.86
+++ core/AudioClip.cpp 5 May 2007 20:43:58 -0000 1.87
@@ -637,6 +637,7 @@
}
m_readSource = rs;
+ m_readSourceId = rs->get_id();
sourceLength = rs->get_nframes();
// If m_length isn't set yet, it means we are importing stuff instead
of reloading from project file.
@@ -969,10 +970,10 @@
m_fades.removeAll(fade);
}
-int AudioClip::get_ref_count( ) const
-{
- return m_refcount;
-}
+// int AudioClip::get_ref_count( ) const
+// {
+// return m_refcount;
+// }
void AudioClip::create_fade_in( )
{
Index: core/AudioClip.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- core/AudioClip.h 30 Apr 2007 13:49:59 -0000 1.45
+++ core/AudioClip.h 5 May 2007 20:43:58 -0000 1.46
@@ -84,7 +84,7 @@
void set_selected(bool selected);
int set_state( const QDomNode& node );
- int get_ref_count() const;
+// int get_ref_count() const;
AudioClip* prev_clip();
AudioClip* next_clip();
Index: core/AudioClipManager.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClipManager.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- core/AudioClipManager.cpp 2 Apr 2007 04:52:49 -0000 1.11
+++ core/AudioClipManager.cpp 5 May 2007 20:43:58 -0000 1.12
@@ -17,13 +17,15 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- $Id: AudioClipManager.cpp,v 1.11 2007/04/02 04:52:49 benjie Exp $
+ $Id: AudioClipManager.cpp,v 1.12 2007/05/05 20:43:58 r_sijrier Exp $
*/
#include "AudioClipManager.h"
#include "Song.h"
#include "AudioClip.h"
+#include "ResourcesManager.h"
+#include "ProjectManager.h"
#include "Track.h"
#include "commands.h"
#include "SnapList.h"
@@ -57,6 +59,7 @@
m_song->get_snap_list()->mark_dirty(clip);
update_last_frame();
+ resources_manager()->set_clip_added(clip);
}
void AudioClipManager::remove_clip( AudioClip * clip )
@@ -68,6 +71,7 @@
}
m_song->get_snap_list()->mark_dirty(clip);
update_last_frame();
+ resources_manager()->set_clip_removed(clip);
}
Index: core/ReadSource.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/ReadSource.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- core/ReadSource.cpp 3 May 2007 14:05:00 -0000 1.27
+++ core/ReadSource.cpp 5 May 2007 20:43:58 -0000 1.28
@@ -45,6 +45,7 @@
: AudioSource(node)
, m_sources()
, m_refcount(0)
+ , m_unrefcount(0)
, m_error(0)
{
Project* project = pm().get_project();
@@ -64,6 +65,7 @@
ReadSource::ReadSource(const QString& dir, const QString& name)
: AudioSource(dir, name)
, m_refcount(0)
+ , m_unrefcount(0)
, m_error(0)
{
SNDFILE* sf;
@@ -83,6 +85,7 @@
ReadSource::ReadSource(const QString& dir, const QString& name, int
channelCount, int fileCount)
: AudioSource(dir, name)
, m_refcount(0)
+ , m_unrefcount(0)
, m_error(0)
{
m_channelCount = channelCount;
@@ -94,6 +97,7 @@
ReadSource::ReadSource()
: AudioSource("", tr("Silence"))
, m_refcount(0)
+ , m_unrefcount(0)
, m_error(0)
{
m_channelCount = 0;
Index: core/ReadSource.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/ReadSource.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- core/ReadSource.h 2 May 2007 05:58:20 -0000 1.20
+++ core/ReadSource.h 5 May 2007 20:43:58 -0000 1.21
@@ -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: ReadSource.h,v 1.20 2007/05/02 05:58:20 benjie Exp $
+$Id: ReadSource.h,v 1.21 2007/05/05 20:43:58 r_sijrier Exp $
*/
#ifndef READSOURCE_H
@@ -53,6 +53,7 @@
int init();
int get_ref_count() const {return m_refcount;}
+ int get_unref_count() const {return m_unrefcount;}
int get_error() const {return m_error;}
int reset_filename(const QString& filename);
void set_active(bool active);
@@ -67,10 +68,13 @@
private:
QList<MonoReader*> m_sources;
int m_refcount;
+ int m_unrefcount;
int m_error;
+ int m_usedByClips;
bool m_silent;
int ref() { return m_refcount++;}
+ int unref(bool b) { if (b) m_unrefcount++; else m_unrefcount--; return
m_unrefcount;}
int add_mono_reader(int channel, int channelNumber, const QString&
fileName);
friend class MonoReader;
Index: core/ResourcesManager.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/ResourcesManager.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- core/ResourcesManager.cpp 2 May 2007 17:18:41 -0000 1.10
+++ core/ResourcesManager.cpp 5 May 2007 20:43:58 -0000 1.11
@@ -88,7 +88,7 @@
// If the clip was refcounted, then it's state has been fully
set
// and likely changed, so we can get the 'new' state from it.
- if (clip->get_ref_count()) {
+ if (m_gettedClips.contains(clip->get_id())) {
audioClipsElement.appendChild(clip->get_state(doc));
} else {
// In case it wasn't we should use the 'old' domNode
which
@@ -305,11 +305,14 @@
{
AudioClip* clip = m_clips.value(id);
+ printf("ResourcesManager: Getting clip with id %lld\n", id);
if (! clip) {
return 0;
}
- if (clip->ref()) {
+ if (m_removedClips.contains(id)) {
+ clip = m_removedClips.take(id);
+ } else if (m_gettedClips.contains(id)) {
PMESG("Creating deep copy of Clip %s", QS_C(clip->get_name()));
clip = clip->create_copy();
@@ -327,6 +330,8 @@
return get_clip(clip->get_id());
}
+ m_gettedClips.insert(id, clip);
+
ReadSource* source = get_readsource(clip->get_readsource_id());
if (source) {
@@ -354,7 +359,11 @@
QList<ReadSource*> ResourcesManager::get_all_audio_sources( ) const
{
- return m_sources.values();
+ QList< ReadSource * > list = m_sources.values();
+ if (m_silentReadSource) {
+ list.removeAll(m_silentReadSource);
+ }
+ return list;
}
QList< AudioClip * > ResourcesManager::get_all_clips() const
@@ -375,6 +384,37 @@
return clips;
}
+void ResourcesManager::set_clip_removed(AudioClip * clip)
+{
+ ReadSource* source = m_sources.value(clip->get_readsource_id());
+ if (source) {
+ source->unref(true);
+ printf("ClipRemoved: refcount, unrefcount: %d, %d\n",
source->get_ref_count(), source->get_unref_count());
+ if (source->get_unref_count() == 0) {
+ emit sourceNoLongerUsed(source);
+ }
+ }
+ m_removedClips.insert(clip->get_id(), clip);
+ emit clipRemoved(clip);
+}
+
+void ResourcesManager::set_clip_added(AudioClip * clip)
+{
+ ReadSource* source = m_sources.value(clip->get_readsource_id());
+ if (source) {
+ source->unref(false);
+ printf("ClipAdded: refcount, unrefcount: %d, %d\n",
source->get_ref_count(), source->get_unref_count());
+ emit sourceBackInUse(source);
+ }
+ m_removedClips.take(clip->get_id());
+ emit clipAdded(clip);
+}
+bool ResourcesManager::is_clip_in_use(qint64 id) const
+{
+ return m_gettedClips.contains(id) && ! m_removedClips.contains(id);
+}
+
//eof
+
Index: core/ResourcesManager.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/ResourcesManager.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- core/ResourcesManager.h 2 May 2007 05:58:20 -0000 1.6
+++ core/ResourcesManager.h 5 May 2007 20:43:58 -0000 1.7
@@ -61,6 +61,10 @@
int remove_clip_from_database(qint64 id);
int undo_remove_clip_from_database(qint64 id);
+ void set_clip_removed(AudioClip* clip);
+ void set_clip_added(AudioClip* clip);
+
+ bool is_clip_in_use(qint64) const;
ReadSource* get_readsource(const QString& fileName);
ReadSource* get_readsource(qint64 id);
@@ -76,6 +80,8 @@
private:
QHash<qint64, ReadSource* > m_sources;
QHash<qint64, AudioClip* > m_clips;
+ QHash<qint64, AudioClip* > m_gettedClips;
+ QHash<qint64, AudioClip* > m_removedClips;
QHash<qint64, AudioClip* > m_deprecatedClips;
ReadSource* m_silentReadSource;
@@ -84,6 +90,11 @@
void sourceAdded();
void sourceRemoved();
void stateChanged();
+ void clipRemoved(AudioClip* clip);
+ void clipAdded(AudioClip* clip);
+ void sourceNoLongerUsed(ReadSource* source);
+ void sourceBackInUse(ReadSource* source);
+ void newSourceCreated(ReadSource* source);
};
Index: traverso/widgets/ResourcesWidget.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/widgets/ResourcesWidget.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- traverso/widgets/ResourcesWidget.cpp 5 May 2007 16:48:31 -0000
1.12
+++ traverso/widgets/ResourcesWidget.cpp 5 May 2007 20:43:58 -0000
1.13
@@ -209,21 +209,28 @@
}
songComboBox->setEnabled(true);
+ ResourcesManager* rsmanager = m_project->get_audiosource_manager();
- connect(m_project->get_audiosource_manager(), SIGNAL(sourceAdded()),
this, SLOT(update_tree_widgets()));
-// connect(m_project->get_audiosource_manager(), SIGNAL(stateChanged()),
this, SLOT(update_tree_widgets()));
+ connect(rsmanager, SIGNAL(sourceAdded()), this,
SLOT(update_tree_widgets()));
+ connect(rsmanager, SIGNAL(clipAdded(AudioClip*)), this,
SLOT(clip_added(AudioClip*)));
+ connect(rsmanager, SIGNAL(clipRemoved(AudioClip*)), this,
SLOT(clip_removed(AudioClip*)));
+ connect(rsmanager, SIGNAL(sourceNoLongerUsed(ReadSource*)), this,
SLOT(source_nolonger_in_use(ReadSource*)));
+ connect(rsmanager, SIGNAL(sourceBackInUse(ReadSource*)), this,
SLOT(source_back_in_use(ReadSource*)));
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()
{
sourcesTreeWidget->clear();
- foreach(ReadSource* rs,
m_project->get_audiosource_manager()->get_all_audio_sources()) {
+ if (!m_project) {
+ return;
+ }
+
+ foreach(ReadSource* rs, resources_manager()->get_all_audio_sources()) {
QTreeWidgetItem* item = new QTreeWidgetItem(sourcesTreeWidget);
+ m_sourceindices.insert(rs->get_id(), item);
QString duration = frame_to_ms(rs->get_nframes(), 44100);
item->setText(0, rs->get_short_name());
item->setText(1, duration);
@@ -238,11 +245,10 @@
item->setForeground(3, QColor(Qt::lightGray));
}
- foreach(AudioClip* clip,
m_project->get_audiosource_manager()->get_all_clips()) {
- if ( ! (clip->get_readsource_id() == rs->get_id())) {
- continue;
- }
+ foreach(AudioClip* clip,
resources_manager()->get_clips_for_source(rs)) {
QTreeWidgetItem* clipitem = new QTreeWidgetItem(item);
+ m_clipindices.insert(clip->get_id(), clipitem);
+ printf("update_tree_widgets: clip is %lld\n",
clip->get_id());
clipitem->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());
@@ -252,7 +258,7 @@
clipitem->setData(0, Qt::UserRole, clip->get_id());
clipitem->setToolTip(0, clip->get_name() + " " +
start + " - " + end);
- if (!clip->get_ref_count()) {
+ if
(resources_manager()->is_clip_in_use(clip->get_id())) {
clipitem->setForeground(0,
QColor(Qt::lightGray));
clipitem->setForeground(1,
QColor(Qt::lightGray));
clipitem->setForeground(2,
QColor(Qt::lightGray));
@@ -280,19 +286,75 @@
void ResourcesWidget::song_combo_box_index_changed(int index)
{
- update_tree_widgets();
+// 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();
+}
+
+void ResourcesWidget::clip_removed(AudioClip * clip)
+{
+ QTreeWidgetItem* item = m_clipindices.value(clip->get_id());
+ for (int i=0; i<5; ++i) {
+ item->setForeground(i, QColor(Qt::lightGray));
+ }
+}
+
+void ResourcesWidget::clip_added(AudioClip * clip)
+{
+ printf("clip_added: clip is %lld\n", clip->get_id());
+ QTreeWidgetItem* item = m_clipindices.value(clip->get_id());
+ if (!item) {
+ add_new_clip_entry(clip);
+ return;
+ }
+ for (int i=0; i<5; ++i) {
+ item->setForeground(i, QColor(Qt::black));
+ }
+}
+
+void ResourcesWidget::source_nolonger_in_use(ReadSource * source)
+{
+ QTreeWidgetItem* item = m_sourceindices.value(source->get_id());
+ if (!item) return;
+ for (int i=0; i<5; ++i) {
+ item->setForeground(i, QColor(Qt::lightGray));
+ }
+}
+
+void ResourcesWidget::source_back_in_use(ReadSource * source)
+{
+ QTreeWidgetItem* item = m_sourceindices.value(source->get_id());
+ for (int i=0; i<5; ++i) {
+ item->setForeground(i, QColor(Qt::black));
+ }
+}
+
+void ResourcesWidget::add_new_clip_entry(AudioClip * clip)
+{
+ QTreeWidgetItem* sourceitem =
m_sourceindices.value(clip->get_readsource_id());
+
+ Q_ASSERT(sourceitem);
+
+ QTreeWidgetItem* clipitem = new QTreeWidgetItem(sourceitem);
+ m_clipindices.insert(clip->get_id(), clipitem);
+ printf("add_new_clip_entry: clip is %lld\n", clip->get_id());
+
+ clipitem->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());
+ clipitem->setText(1, frame_to_ms(clip->get_length(), clip->get_rate()));
+ clipitem->setText(2, start);
+ clipitem->setText(3, end);
+ clipitem->setData(0, Qt::UserRole, clip->get_id());
+ clipitem->setToolTip(0, clip->get_name() + " " + start + " - " + end);
}
Index: traverso/widgets/ResourcesWidget.h
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/widgets/ResourcesWidget.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- traverso/widgets/ResourcesWidget.h 3 May 2007 22:43:12 -0000 1.4
+++ traverso/widgets/ResourcesWidget.h 5 May 2007 20:43:58 -0000 1.5
@@ -28,6 +28,9 @@
class Project;
class Song;
class FileWidget;
+class AudioClip;
+class ReadSource;
+class QTreeWidgetItem;
class ResourcesWidget : public QWidget, protected Ui::ResourcesWidget
{
@@ -42,6 +45,10 @@
private:
Project* m_project;
FileWidget* m_filewidget;
+ QHash<qint64, QTreeWidgetItem*> m_clipindices;
+ QHash<qint64, QTreeWidgetItem*> m_sourceindices;
+
+ void add_new_clip_entry(AudioClip* clip);
private slots:
@@ -51,6 +58,11 @@
void song_combo_box_index_changed(int index);
void song_added(Song* song);
void song_removed(Song* song);
+
+ void clip_removed(AudioClip* clip);
+ void clip_added(AudioClip* clip);
+ void source_nolonger_in_use(ReadSource* source);
+ void source_back_in_use(ReadSource* source);
};
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Traverso-commit] traverso/src commands/RemoveClip.cpp commands/R...,
Remon Sijrier <=