[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Traverso-commit] traverso/src core/AudioClip.cpp core/AudioClip....
From: |
Remon Sijrier |
Subject: |
[Traverso-commit] traverso/src core/AudioClip.cpp core/AudioClip.... |
Date: |
Fri, 17 Aug 2007 00:18:31 +0000 |
CVSROOT: /sources/traverso
Module name: traverso
Changes by: Remon Sijrier <r_sijrier> 07/08/17 00:18:31
Modified files:
src/core : AudioClip.cpp AudioClip.h AudioClipManager.cpp
AudioSource.cpp AudioSource.h Debugger.cpp
DiskIO.cpp DiskIO.h ReadSource.cpp ReadSource.h
ResourcesManager.cpp Song.cpp Song.h
src/engine : defines.h
Log message:
* More conversion to TimeRef, this time in ReadSource and AudioClip.
I'm not quite sure why in AudioClip::process() in some cases the readsources
rate has to be used, and in other the rate of the audiodevice....
* When the audiodevices samplerate changes, the ReadSources readbuffers
need to be re-sized, else the logic for detecting if enough data is in the
buffer no longer is valid!
* Added a number of operators for TimeRef to make it work just like
nframes_t
* Moved set/get_state() from AudioSource to ReadSource since it
belonged there.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.cpp?cvsroot=traverso&r1=1.125&r2=1.126
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.h?cvsroot=traverso&r1=1.58&r2=1.59
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClipManager.cpp?cvsroot=traverso&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioSource.cpp?cvsroot=traverso&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioSource.h?cvsroot=traverso&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Debugger.cpp?cvsroot=traverso&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/DiskIO.cpp?cvsroot=traverso&r1=1.45&r2=1.46
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/DiskIO.h?cvsroot=traverso&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ReadSource.cpp?cvsroot=traverso&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ReadSource.h?cvsroot=traverso&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ResourcesManager.cpp?cvsroot=traverso&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Song.cpp?cvsroot=traverso&r1=1.130&r2=1.131
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Song.h?cvsroot=traverso&r1=1.64&r2=1.65
http://cvs.savannah.gnu.org/viewcvs/traverso/src/engine/defines.h?cvsroot=traverso&r1=1.14&r2=1.15
Patches:
Index: core/AudioClip.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.cpp,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -b -r1.125 -r1.126
--- core/AudioClip.cpp 16 Aug 2007 14:26:50 -0000 1.125
+++ core/AudioClip.cpp 17 Aug 2007 00:18:29 -0000 1.126
@@ -66,7 +66,6 @@
, m_name(name)
{
PENTERCONS;
- m_length = sourceStartFrame = sourceEndFrame = trackEndFrame = 0;
m_isMuted=false;
m_id = create_id();
m_readSourceId = m_songId = 0;
@@ -77,6 +76,7 @@
AudioClip::AudioClip(const QDomNode& node)
: ContextItem()
, Snappable()
+ , m_readSource(0)
{
PENTERCONS;
QDomNode clipNode = node.firstChild();
@@ -89,9 +89,11 @@
m_songId = e.attribute("sheet", "0").toLongLong();
m_name = e.attribute( "clipname", "" ) ;
m_isMuted = e.attribute( "mute", "" ).toInt();
- m_length = e.attribute( "length", "0" ).toUInt();
- sourceStartFrame = e.attribute( "sourcestart", "" ).toUInt();
- sourceEndFrame = sourceStartFrame + m_length;
+ // FIXME!!!!!!!
+ m_length = TimeRef(e.attribute( "length", "0" ).toUInt(), 44100);
+ m_sourceStartLocation = TimeRef(e.attribute( "sourcestart", ""
).toUInt(), 44100);
+
+ m_sourceEndLocation = m_sourceStartLocation + m_length;
set_track_start_frame( e.attribute( "trackstart", "" ).toUInt());
m_domNode = node.cloneNode();
init();
@@ -145,10 +147,12 @@
m_songId = e.attribute("sheet", "0").toLongLong();
m_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());
+ // FIXME!!!!!!!!
+ m_sourceStartLocation = TimeRef(e.attribute( "sourcestart", ""
).toUInt(), 44100);
+ m_length = TimeRef(e.attribute( "length", "0" ).toUInt(), 44100);
+
+ m_sourceEndLocation = m_sourceStartLocation + m_length;
+ set_track_start_frame(e.attribute( "trackstart", "" ).toUInt());
emit stateChanged();
@@ -183,9 +187,9 @@
QDomNode AudioClip::get_state( QDomDocument doc )
{
QDomElement node = doc.createElement("Clip");
- node.setAttribute("trackstart", trackStartFrame);
- node.setAttribute("sourcestart", sourceStartFrame);
- node.setAttribute("length", m_length);
+ node.setAttribute("trackstart",
m_trackStartLocation.to_frame(get_rate()));
+ node.setAttribute("sourcestart",
m_sourceStartLocation.to_frame(get_rate()));
+ node.setAttribute("length", m_length.to_frame(get_rate()));
node.setAttribute("mute", m_isMuted);
node.setAttribute("take", m_isTake);
node.setAttribute("clipname", m_name );
@@ -247,37 +251,39 @@
}
-void AudioClip::set_left_edge(long newFrame)
+void AudioClip::set_left_edge(long frame)
{
- if (newFrame < 0) {
- newFrame = 0;
+ if (frame < 0) {
+ frame = 0;
}
- if (newFrame < (long)trackStartFrame) {
+ TimeRef newLeftLocation(frame, get_rate());
- int availableFramesLeft = sourceStartFrame;
+ if (newLeftLocation < m_trackStartLocation) {
- int movingToLeft = trackStartFrame - newFrame;
+ TimeRef availableTimeLeft = m_sourceStartLocation;
- if (movingToLeft > availableFramesLeft) {
- movingToLeft = availableFramesLeft;
+ TimeRef movingToLeft = m_trackStartLocation - newLeftLocation;
+
+ if (movingToLeft > availableTimeLeft) {
+ movingToLeft = availableTimeLeft;
}
- trackStartFrame -= movingToLeft;
- set_source_start_frame( sourceStartFrame - movingToLeft );
+ m_trackStartLocation -= movingToLeft;
+ set_source_start_location( m_sourceStartLocation - movingToLeft
);
- } else if (newFrame > (long)trackStartFrame) {
+ } else if (newLeftLocation > m_trackStartLocation) {
- int availableFramesRight = m_length;
+ TimeRef availableTimeRight = m_length;
- int movingToRight = newFrame - trackStartFrame;
+ TimeRef movingToRight = newLeftLocation - m_trackStartLocation;
- if (movingToRight > availableFramesRight - 4) {
- movingToRight = availableFramesRight - 4;
+ if (movingToRight > (availableTimeRight - TimeRef(4,
get_rate())) ) {
+ movingToRight = (availableTimeRight - TimeRef(4,
get_rate()));
}
- trackStartFrame += movingToRight;
- set_source_start_frame( sourceStartFrame + movingToRight );
+ m_trackStartLocation += movingToRight;
+ set_source_start_location( m_sourceStartLocation +
movingToRight );
} else {
return;
@@ -286,37 +292,39 @@
emit positionChanged(this);
}
-void AudioClip::set_right_edge(long newFrame)
+void AudioClip::set_right_edge(long frame)
{
- if (newFrame < 0) {
- newFrame = 0;
+ if (frame < 0) {
+ frame = 0;
}
- if (newFrame > (long)trackEndFrame) {
+ TimeRef newRightLocation(frame, get_rate());
+
+ if (newRightLocation > m_trackEndLocation) {
- int availableFramesRight = sourceLength - sourceEndFrame;
+ TimeRef availableTimeRight = m_sourceLength -
m_sourceEndLocation;
- int movingToRight = newFrame - trackEndFrame;
+ TimeRef movingToRight = newRightLocation - m_trackEndLocation;
- if (movingToRight > availableFramesRight) {
- movingToRight = availableFramesRight;
+ if (movingToRight > availableTimeRight) {
+ movingToRight = availableTimeRight;
}
- set_track_end_frame( trackEndFrame + movingToRight );
- set_source_end_frame( sourceEndFrame + movingToRight );
+ set_track_end_location( m_trackEndLocation + movingToRight );
+ set_source_end_location( m_sourceEndLocation + movingToRight );
- } else if (newFrame < (long)trackEndFrame) {
+ } else if (newRightLocation < m_trackEndLocation) {
- int availableFramesLeft = m_length;
+ TimeRef availableTimeLeft = m_length;
- int movingToLeft = trackEndFrame - newFrame;
+ TimeRef movingToLeft = m_trackEndLocation - newRightLocation;
- if (movingToLeft > availableFramesLeft - 4) {
- movingToLeft = availableFramesLeft - 4;
+ if (movingToLeft > availableTimeLeft - TimeRef(4, get_rate())) {
+ movingToLeft = availableTimeLeft - TimeRef(4,
get_rate());
}
- set_track_end_frame( trackEndFrame - movingToLeft );
- set_source_end_frame( sourceEndFrame - movingToLeft);
+ set_track_end_location( m_trackEndLocation - movingToLeft );
+ set_source_end_location( m_sourceEndLocation - movingToLeft);
} else {
return;
@@ -325,32 +333,32 @@
emit positionChanged(this);
}
-void AudioClip::set_source_start_frame(nframes_t frame)
+void AudioClip::set_source_start_location(const TimeRef& location)
{
- sourceStartFrame = frame;
- m_length = sourceEndFrame - sourceStartFrame;
+ m_sourceStartLocation = location;
+ m_length = m_sourceEndLocation - m_sourceStartLocation;
}
-void AudioClip::set_source_end_frame(nframes_t frame)
+void AudioClip::set_source_end_location(const TimeRef& location)
{
- sourceEndFrame = frame;
- m_length = sourceEndFrame - sourceStartFrame;
+ m_sourceEndLocation = location;
+ m_length = m_sourceEndLocation - m_sourceStartLocation;
}
void AudioClip::set_track_start_frame(nframes_t newTrackStartFrame)
{
- trackStartFrame = newTrackStartFrame;
+ m_trackStartLocation = TimeRef(newTrackStartFrame, get_rate());
- set_track_end_frame(trackStartFrame + m_length);
+ set_track_end_location(m_trackStartLocation + m_length);
emit positionChanged(this);
}
-void AudioClip::set_track_end_frame( nframes_t endFrame )
+void AudioClip::set_track_end_location(const TimeRef& location)
{
-// PWARN("trackEndFrame is %d", endFrame);
- trackEndFrame = endFrame;
- emit trackEndFrameChanged();
+// PWARN("m_trackEndLocation is %d", endFrame);
+ m_trackEndLocation = location;
+ emit trackEndLocationChanged();
}
void AudioClip::set_fade_in(nframes_t b)
@@ -409,36 +417,32 @@
Q_ASSERT(m_readSource);
-/* if (channel >= m_readSource->get_channel_count()) {
- return 1;
- }*/
-
AudioBus* bus = m_song->get_render_bus();
nframes_t mix_pos;
audio_sample_t* mixdown[get_channels()];
- nframes_t transportFrame = m_song->get_transport_frame();
- nframes_t upperRange = transportFrame + nframes;
+ TimeRef transportLocation = m_song->get_transport_location();
+ TimeRef upperRange = TimeRef(transportLocation.to_frame(get_rate()) +
nframes, get_rate());
+
+ if ( (m_trackStartLocation < upperRange) && (m_trackEndLocation >
transportLocation) ) {
+ if (transportLocation < m_trackStartLocation) {
+ uint offset = (m_trackStartLocation -
transportLocation).to_frame(get_rate());
+ mix_pos = m_sourceStartLocation.to_frame(get_rate());
- if ( (trackStartFrame < upperRange) && (trackEndFrame > transportFrame)
) {
- if (transportFrame < trackStartFrame) {
- uint offset = trackStartFrame - transportFrame;
- mix_pos = sourceStartFrame;
-// mixdown = buffer + offset;
for (int chan=0; chan<bus->get_channel_count(); ++chan)
{
mixdown[chan] = bus->get_buffer(chan, nframes)
+ offset;
}
nframes = nframes - offset;
} else {
- mix_pos = transportFrame - trackStartFrame +
sourceStartFrame;
-// mixdown = buffer;
+ mix_pos = (transportLocation - m_trackStartLocation +
m_sourceStartLocation).to_frame(audiodevice().get_sample_rate());
+
for (int chan=0; chan<bus->get_channel_count(); ++chan)
{
mixdown[chan] = bus->get_buffer(chan, nframes);
}
}
- if (trackEndFrame < upperRange) {
- nframes -= (upperRange - trackEndFrame);
+ if (m_trackEndLocation < upperRange) {
+ nframes -= (upperRange -
m_trackEndLocation).to_frame(get_rate());
}
} else {
return 0;
@@ -466,7 +470,7 @@
m_fades.at(i)->process(mixdown[chan], read_frames);
}
- m_fader->process_gain(mixdown[chan],
(m_song->get_transport_frame() - (trackStartFrame - sourceStartFrame)),
read_frames);
+ m_fader->process_gain(mixdown[chan], ((transportLocation -
m_trackStartLocation - m_sourceStartLocation).to_frame(get_rate())),
read_frames);
Mixer::apply_gain_to_buffer(bus->get_buffer(chan, nframes),
nframes, get_gain());
}
@@ -523,7 +527,7 @@
return -1;
}
- sourceStartFrame = 0;
+ m_sourceStartLocation = TimeRef(0);
m_isTake = 1;
m_recordingStatus = RECORDING;
int channelcount;
@@ -658,18 +662,18 @@
m_readSource = rs;
m_readSourceId = rs->get_id();
- sourceLength = rs->get_nframes();
+ m_sourceLength = rs->get_length();
// If m_length isn't set yet, it means we are importing stuff instead
of reloading from project file.
// it's a bit weak this way, hopefull I'll get up something better in
the future.
// The positioning-length-offset and such stuff is still a bit weak :(
// NOTE: don't change, audio recording (finish_writesource()) assumes
there is checked for length == 0 !!!
if (m_length == 0) {
- sourceEndFrame = rs->get_nframes();
- m_length = sourceEndFrame;
+ m_sourceEndLocation = rs->get_length();
+ m_length = m_sourceEndLocation;
}
- set_track_end_frame( trackStartFrame + sourceLength - sourceStartFrame);
+ set_track_end_location(m_trackStartLocation + m_sourceLength -
m_sourceStartLocation);
set_sources_active_state();
@@ -833,12 +837,12 @@
nframes_t AudioClip::get_source_length( ) const
{
- return sourceLength;
+ return m_sourceLength.to_frame(get_rate());
}
nframes_t AudioClip::get_length() const
{
- return m_length;
+ return m_length.to_frame(get_rate());
}
int AudioClip::recording_state( ) const
@@ -848,22 +852,22 @@
nframes_t AudioClip::get_source_end_frame( ) const
{
- return sourceEndFrame;
+ return m_sourceEndLocation.to_frame(get_rate());
}
nframes_t AudioClip::get_source_start_frame( ) const
{
- return sourceStartFrame;
+ return m_sourceStartLocation.to_frame(get_rate());
}
nframes_t AudioClip::get_track_end_frame( ) const
{
- return trackEndFrame;
+ return m_trackEndLocation.to_frame(get_rate());
}
nframes_t AudioClip::get_track_start_frame( ) const
{
- return trackStartFrame;
+ return m_trackStartLocation.to_frame(get_rate());
}
@@ -915,7 +919,7 @@
}
for (uint i=0; i<m_readSource->get_channel_count(); ++i) {
- double amp =
get_peak_for_channel(i)->get_max_amplitude(sourceStartFrame, sourceEndFrame);
+ double amp =
get_peak_for_channel(i)->get_max_amplitude(m_sourceStartLocation.to_frame(get_rate()),
m_sourceEndLocation.to_frame(get_rate()));
if (amp == 0.0f) {
printf("AudioClip::normalization: max amplitude ==
0\n");
Index: core/AudioClip.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.h,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- core/AudioClip.h 15 Aug 2007 20:15:49 -0000 1.58
+++ core/AudioClip.h 17 Aug 2007 00:18:29 -0000 1.59
@@ -140,12 +140,13 @@
QString m_name;
QByteArray m_captureBusName;
- nframes_t trackStartFrame;
- nframes_t trackEndFrame;
- nframes_t sourceEndFrame;
- nframes_t sourceStartFrame;
- nframes_t sourceLength;
- nframes_t m_length;
+
+ mutable TimeRef m_trackStartLocation;
+ mutable TimeRef m_trackEndLocation;
+ mutable TimeRef m_sourceEndLocation;
+ mutable TimeRef m_sourceStartLocation;
+ mutable TimeRef m_sourceLength;
+ mutable TimeRef m_length;
int m_isSelected;
bool m_isTake;
@@ -160,9 +161,9 @@
void create_fade_in();
void create_fade_out();
void init();
- void set_source_end_frame(nframes_t frame);
- void set_source_start_frame(nframes_t frame);
- void set_track_end_frame(nframes_t endFrame);
+ void set_source_end_location(const TimeRef& location);
+ void set_source_start_location(const TimeRef& location);
+ void set_track_end_location(const TimeRef& location);
void set_sources_active_state();
void process_capture(nframes_t nframes);
@@ -176,7 +177,7 @@
void muteChanged();
void lockChanged();
void positionChanged(Snappable*);
- void trackEndFrameChanged();
+ void trackEndLocationChanged();
void fadeAdded(FadeCurve*);
void fadeRemoved(FadeCurve*);
void recordingFinished();
Index: core/AudioClipManager.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClipManager.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- core/AudioClipManager.cpp 27 Jun 2007 13:27:07 -0000 1.15
+++ core/AudioClipManager.cpp 17 Aug 2007 00:18:29 -0000 1.16
@@ -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: AudioClipManager.cpp,v 1.15 2007/06/27 13:27:07 r_sijrier Exp $
+ $Id: AudioClipManager.cpp,v 1.16 2007/08/17 00:18:29 r_sijrier Exp $
*/
#include "AudioClipManager.h"
@@ -56,7 +56,7 @@
m_clips.append( clip );
- connect(clip, SIGNAL(trackEndFrameChanged()), this,
SLOT(update_last_frame()));
+ connect(clip, SIGNAL(trackEndLocationChanged()), this,
SLOT(update_last_frame()));
connect(clip, SIGNAL(positionChanged(Snappable*)),
m_song->get_snap_list(), SLOT(mark_dirty(Snappable*)));
m_song->get_snap_list()->mark_dirty(clip);
Index: core/AudioSource.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioSource.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- core/AudioSource.cpp 16 Aug 2007 14:26:50 -0000 1.27
+++ core/AudioSource.cpp 17 Aug 2007 00:18:29 -0000 1.28
@@ -47,13 +47,12 @@
// This constructor is called for existing (recorded/imported) audio sources
-AudioSource::AudioSource(const QDomNode node)
+AudioSource::AudioSource()
: m_dir("")
, m_name("")
, m_fileName("")
, m_wasRecording(false)
{
- set_state(node);
}
@@ -62,53 +61,6 @@
PENTERDES;
}
-
-QDomNode AudioSource::get_state( QDomDocument doc )
-{
- QDomElement node = doc.createElement("Source");
- node.setAttribute("channelcount", m_channelCount);
- node.setAttribute("origsheetid", m_origSongId);
- node.setAttribute("dir", m_dir);
- node.setAttribute("id", m_id);
- node.setAttribute("name", m_name);
- node.setAttribute("origbitdepth", m_origBitDepth);
- node.setAttribute("wasrecording", m_wasRecording);
- node.setAttribute("length", m_length);
- node.setAttribute("rate", m_rate);
- node.setAttribute("decoder", m_decodertype);
-
- return node;
-}
-
-
-int AudioSource::set_state( const QDomNode & node )
-{
- PENTER;
-
- QDomElement e = node.toElement();
- m_channelCount = e.attribute("channelcount", "0").toInt();
- m_origSongId = e.attribute("origsheetid", "0").toLongLong();
- set_dir( e.attribute("dir", "" ));
- m_id = e.attribute("id", "").toLongLong();
- m_length = e.attribute("length", "0").toUInt();
- m_rate = e.attribute("rate", "0").toUInt();
- m_origBitDepth = e.attribute("origbitdepth", "0").toInt();
- m_wasRecording = e.attribute("wasrecording", "0").toInt();
- m_decodertype = e.attribute("decoder", "");
-
- // For older project files, this should properly detect if the
- // audio source was a recording or not., in fact this should suffice
- // and the flag wasrecording would be unneeded, but oh well....
- if (m_origSongId != 0) {
- m_wasRecording = true;
- }
-
- set_name( e.attribute("name", "No name supplied?" ));
-
- return 1;
-}
-
-
void AudioSource::set_name(const QString& name)
{
m_name = name;
Index: core/AudioSource.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioSource.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- core/AudioSource.h 16 Aug 2007 14:26:50 -0000 1.24
+++ core/AudioSource.h 17 Aug 2007 00:18:30 -0000 1.25
@@ -25,7 +25,6 @@
#include "defines.h"
#include <QObject>
-#include <QDomDocument>
#include "RingBufferNPT.h"
@@ -36,19 +35,14 @@
class AudioSource : public QObject
{
public :
+ AudioSource();
AudioSource(const QString& dir, const QString& name);
- AudioSource(const QDomNode node);
- AudioSource(){};
~AudioSource();
void set_name(const QString& name);
void set_dir(const QString& name);
void set_original_bit_depth(uint bitDepth);
void set_created_by_song(qint64 id);
- int set_state( const QDomNode& node );
-
-
- QDomNode get_state(QDomDocument doc);
QString get_filename() const;
QString get_dir() const;
QString get_name() const;
@@ -73,10 +67,8 @@
QString m_shortName;
uint m_origBitDepth;
QString m_fileName;
- nframes_t m_length;
uint m_rate;
int m_wasRecording;
- QString m_decodertype;
};
Index: core/Debugger.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Debugger.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- core/Debugger.cpp 20 Apr 2006 14:51:39 -0000 1.1
+++ core/Debugger.cpp 17 Aug 2007 00:18:30 -0000 1.2
@@ -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: Debugger.cpp,v 1.1 2006/04/20 14:51:39 r_sijrier Exp $
+ $Id: Debugger.cpp,v 1.2 2007/08/17 00:18:30 r_sijrier Exp $
*/
#include <stdlib.h>
@@ -351,7 +351,7 @@
++nptrs;
}
if(traceFlag) {
- printf("Allocated %u bytes at address %p (file: %s, line:
%ld)\n", siz, p, file, line);
+ printf("Allocated %.2f KBytes at address %p (file: %s, line:
%ld)\n", (float)siz/1024, p, file, line);
}
fflush(NULL);
return p;
@@ -372,8 +372,10 @@
free(p);
assert(nptrs > 0);
delPointer(p);
- if(traceFlag)
+ if(traceFlag) {
+ if (memMap[i].size > 1024)
printf("Deleted %u bytes at address %p, file: %s,
line: %ld\n", memMap[i].size, p, memMap[i].file, memMap[i].line);
+ }
} else if(!p && activeFlag)
printf("Attempt to delete unknown pointer: %p\n", p);
fflush(NULL);
Index: core/DiskIO.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/DiskIO.cpp,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- core/DiskIO.cpp 16 Aug 2007 14:26:50 -0000 1.45
+++ core/DiskIO.cpp 17 Aug 2007 00:18:30 -0000 1.46
@@ -183,7 +183,7 @@
*
* @param position The position to seek too
*/
-void DiskIO::seek( nframes_t position )
+void DiskIO::seek()
{
PENTER;
@@ -194,11 +194,14 @@
m_stopWork = 0;
m_seeking = true;
+ TimeRef location = m_song->get_new_transport_location();
+
foreach(ReadSource* source, m_readSources) {
if (m_sampleRateChanged) {
source->output_rate_changed();
+ source->prepare_buffer();
}
- source->rb_seek_to_file_position(position);
+ source->rb_seek_to_file_position(location);
}
m_sampleRateChanged = false;
Index: core/DiskIO.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/DiskIO.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- core/DiskIO.h 16 Aug 2007 14:26:50 -0000 1.21
+++ core/DiskIO.h 17 Aug 2007 00:18:30 -0000 1.22
@@ -98,7 +98,7 @@
friend class DiskIOThread;
public slots:
- void seek(uint position);
+ void seek();
void start_io();
void stop_io();
Index: core/ReadSource.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/ReadSource.cpp,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- core/ReadSource.cpp 16 Aug 2007 14:26:50 -0000 1.49
+++ core/ReadSource.cpp 17 Aug 2007 00:18:30 -0000 1.50
@@ -46,12 +46,16 @@
// This constructor is called for existing (recorded/imported) audio sources
ReadSource::ReadSource(const QDomNode node)
- : AudioSource(node)
+ : AudioSource()
{
+
+ set_state(node);
+
private_init();
Project* project = pm().get_project();
+ // FIXME The check below no longer makes sense!!!!!
// Check if the audiofile exists in our project audiosources dir
// and give it priority over the dir as given by the project.tpf file
// This makes it possible to move project directories without Traverso
being
@@ -93,7 +97,6 @@
m_silent = false;
m_name = name + "-" + QString::number(m_id);
m_fileName = m_dir + m_name;
- m_length = 0;
m_rate = pm().get_project()->get_rate();
m_wasRecording = true;
m_shortName = m_name.left(m_name.length() - 20);
@@ -137,6 +140,51 @@
}
}
+QDomNode ReadSource::get_state( QDomDocument doc )
+{
+ QDomElement node = doc.createElement("Source");
+ node.setAttribute("channelcount", m_channelCount);
+ node.setAttribute("origsheetid", m_origSongId);
+ node.setAttribute("dir", m_dir);
+ node.setAttribute("id", m_id);
+ node.setAttribute("name", m_name);
+ node.setAttribute("origbitdepth", m_origBitDepth);
+ node.setAttribute("wasrecording", m_wasRecording);
+ node.setAttribute("length", m_length.to_frame(m_rate));
+ node.setAttribute("rate", m_rate);
+ node.setAttribute("decoder", m_decodertype);
+
+ return node;
+}
+
+
+int ReadSource::set_state( const QDomNode & node )
+{
+ PENTER;
+
+ QDomElement e = node.toElement();
+ m_channelCount = e.attribute("channelcount", "0").toInt();
+ m_origSongId = e.attribute("origsheetid", "0").toLongLong();
+ set_dir( e.attribute("dir", "" ));
+ m_id = e.attribute("id", "").toLongLong();
+ m_rate = e.attribute("rate", "0").toUInt();
+ m_length = TimeRef(e.attribute("length", "0").toUInt(), m_rate);
+ m_origBitDepth = e.attribute("origbitdepth", "0").toInt();
+ m_wasRecording = e.attribute("wasrecording", "0").toInt();
+ m_decodertype = e.attribute("decoder", "");
+
+ // For older project files, this should properly detect if the
+ // audio source was a recording or not., in fact this should suffice
+ // and the flag wasrecording would be unneeded, but oh well....
+ if (m_origSongId != 0) {
+ m_wasRecording = true;
+ }
+
+ set_name( e.attribute("name", "No name supplied?" ));
+
+ return 1;
+}
+
int ReadSource::init( )
{
@@ -150,7 +198,7 @@
m_rate = project->get_rate();
if (m_silent) {
- m_length = INT_MAX;
+ m_length = TimeRef(UINT_MAX);
m_channelCount = 0;
m_origBitDepth = project->get_bitdepth();
return 1;
@@ -161,9 +209,6 @@
return (m_error = INVALID_CHANNEL_COUNT);
}
-
- m_rbFileReadPos = 0;
- m_rbRelativeFileReadPos = 0;
m_rbReady = 0;
m_needSync = 0;
m_syncInProgress = 0;
@@ -210,8 +255,8 @@
return ZERO_CHANNELS;
}
- m_length = m_audioReader->get_length();
m_rate = m_audioReader->get_file_rate();
+ m_length = TimeRef(m_audioReader->get_length(), m_rate);
m_bufferstatus = new BufferStatus;
@@ -271,9 +316,9 @@
m_clip = clip;
}
-nframes_t ReadSource::get_nframes( ) const
+const nframes_t ReadSource::get_nframes( ) const
{
- return m_length;
+ return m_length.to_frame(m_rate);
}
int ReadSource::set_file(const QString & filename)
@@ -315,18 +360,20 @@
return 0;
}
- if (start != m_rbRelativeFileReadPos) {
- int available = m_buffers.at(0)->read_space();
+ nframes_t relativepos = m_rbRelativeFileReadPos.to_frame(m_rate);
+
+ if (start != relativepos) {
+ uint available = m_buffers.at(0)->read_space();
// printf("start %d, m_rbFileReadPos %d\n", start,
m_rbRelativeFileReadPos);
- if ( (start > m_rbRelativeFileReadPos) &&
(m_rbRelativeFileReadPos + available) > (start + count)) {
- int advance = start - m_rbRelativeFileReadPos;
+ if ( (start > relativepos) && (relativepos + available) >
(start + count)) {
+ uint advance = start - relativepos;
if (available < advance) {
printf("available < advance !!!!!!!\n");
}
for (int i=m_buffers.size()-1; i>=0; --i) {
m_buffers.at(i)->increment_read_ptr(advance);
}
- m_rbRelativeFileReadPos += advance;
+ m_rbRelativeFileReadPos.add_frames(advance, m_rate);
} else {
start_resync(start + (m_clip->get_track_start_frame() +
m_clip->get_source_start_frame()));
return 0;
@@ -345,7 +392,7 @@
}
- m_rbRelativeFileReadPos += readcount;
+ m_rbRelativeFileReadPos.add_frames(readcount, m_rate);
return readcount;
}
@@ -353,23 +400,23 @@
int ReadSource::rb_file_read(DecodeBuffer* buffer, nframes_t cnt)
{
- int readFrames = file_read(buffer, m_rbFileReadPos, cnt);
- m_rbFileReadPos += readFrames;
+ int readFrames = file_read(buffer, m_rbFileReadPos.to_frame(m_rate),
cnt);
+ m_rbFileReadPos.add_frames(readFrames, m_rate);
return readFrames;
}
-void ReadSource::rb_seek_to_file_position( nframes_t position )
+void ReadSource::rb_seek_to_file_position(TimeRef& position)
{
Q_ASSERT(m_clip);
// printf("rb_seek_to_file_position:: seeking to %d\n", position);
// calculate position relative to the file!
- long fileposition = position - (m_clip->get_track_start_frame() +
m_clip->get_source_start_frame());
+ TimeRef fileposition = position -
TimeRef(m_clip->get_track_start_frame() + m_clip->get_source_start_frame(),
m_rate);
- if ((long)m_rbFileReadPos == fileposition) {
+ if (m_rbFileReadPos == fileposition) {
// printf("ringbuffer allready at position %d\n", position);
return;
}
@@ -384,7 +431,8 @@
// Setting a songs new position is on 1024, and NOT
// 1023.. Hmm, something isn't correct here, but at least
substract 1
// to make this thing work!
- fileposition = m_clip->get_source_start_frame() - 1;
+ // TODO check if this is still needed!
+ fileposition = TimeRef(m_clip->get_source_start_frame() - 1,
m_rate);
}
// printf("rb_seek_to_file_position:: seeking to relative pos: %d\n",
fileposition);
@@ -427,8 +475,9 @@
// If we are nearing the end of the source file it could be
possible
// we only need to read the last samples which is smaller in
size then
// chunksize. If so, set toRead to m_source->m_length -
rbFileReasPos
- if ( (int) (m_length - m_rbFileReadPos) <= m_chunkSize) {
- toRead = m_length - m_rbFileReadPos;
+ nframes_t available = (m_length -
m_rbFileReadPos).to_frame(m_rate);
+ if (available <= m_chunkSize) {
+ toRead = available;
} else {
printf("ReadSource:: chunkCount == 0, but not at end of
file, this shouldn't happen!!\n");
return;
@@ -454,7 +503,7 @@
void ReadSource::start_resync( nframes_t position )
{
-// printf("starting resync!\n");
+ printf("starting resync!\n");
m_syncPos = position;
m_rbReady = 0;
m_needSync = 1;
@@ -462,7 +511,7 @@
void ReadSource::finish_resync()
{
-// printf("sync finished\n");
+ printf("sync finished\n");
m_needSync = 0;
m_bufferUnderRunDetected = 0;
m_rbReady = 1;
@@ -477,7 +526,8 @@
}
if (!m_syncInProgress) {
- rb_seek_to_file_position(m_syncPos);
+ TimeRef position(m_syncPos, m_rate);
+ rb_seek_to_file_position(position);
m_syncInProgress = 1;
}
@@ -501,6 +551,12 @@
Q_ASSERT(m_clip);
+ for (int i=0; i<m_buffers.size();++i) {
+ delete m_buffers.at(i);
+ }
+
+ m_buffers.clear();
+
float size = config().get_property("Hardware", "readbuffersize",
1.0).toDouble();
m_bufferSize = (int) (size * audiodevice().get_sample_rate());
Index: core/ReadSource.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/ReadSource.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- core/ReadSource.h 15 Aug 2007 20:07:42 -0000 1.33
+++ core/ReadSource.h 17 Aug 2007 00:18:30 -0000 1.34
@@ -24,6 +24,9 @@
#include "AudioSource.h"
+#include <QDomDocument>
+
+
class AbstractAudioReader;
class AudioClip;
struct BufferStatus;
@@ -48,8 +51,11 @@
ReadSource* deep_copy();
+ int set_state( const QDomNode& node );
+ QDomNode get_state(QDomDocument doc);
+
int rb_read(audio_sample_t** dest, nframes_t start, nframes_t cnt);
- void rb_seek_to_file_position(nframes_t position);
+ void rb_seek_to_file_position(TimeRef& position);
int file_read(DecodeBuffer* buffer, nframes_t start, nframes_t cnt)
const;
@@ -59,7 +65,8 @@
void set_active(bool active);
void set_audio_clip(AudioClip* clip);
- nframes_t get_nframes() const;
+ const nframes_t get_nframes() const;
+ const TimeRef& get_length() const {return m_length;}
void sync(DecodeBuffer* buffer);
void process_ringbuffer(DecodeBuffer* buffer, bool seeking=false);
@@ -76,8 +83,8 @@
int m_refcount;
int m_error;
bool m_silent;
- nframes_t m_rbFileReadPos;
- nframes_t m_rbRelativeFileReadPos;
+ TimeRef m_rbFileReadPos;
+ TimeRef m_rbRelativeFileReadPos;
volatile size_t m_syncPos;
volatile size_t m_rbReady;
volatile size_t m_needSync;
@@ -86,6 +93,9 @@
volatile size_t m_bufferUnderRunDetected;
bool m_syncInProgress;
+ mutable TimeRef m_length;
+ QString m_decodertype;
+
BufferStatus* m_bufferstatus;
int ref() { return m_refcount++;}
Index: core/ResourcesManager.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/ResourcesManager.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- core/ResourcesManager.cpp 18 Jul 2007 13:13:07 -0000 1.21
+++ core/ResourcesManager.cpp 17 Aug 2007 00:18:30 -0000 1.22
@@ -74,7 +74,7 @@
QDomElement audioSourcesElement = doc.createElement("AudioSources");
foreach(SourceData* data, m_sources) {
- AudioSource* source = (AudioSource*)data->source;
+ ReadSource* source = data->source;
audioSourcesElement.appendChild(source->get_state(doc));
}
Index: core/Song.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Song.cpp,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -b -r1.130 -r1.131
--- core/Song.cpp 14 Aug 2007 10:49:55 -0000 1.130
+++ core/Song.cpp 17 Aug 2007 00:18:30 -0000 1.131
@@ -127,7 +127,7 @@
m_diskio = new DiskIO(this);
- connect(this, SIGNAL(seekStart(uint)), m_diskio, SLOT(seek(uint)),
Qt::QueuedConnection);
+ connect(this, SIGNAL(seekStart()), m_diskio, SLOT(seek()),
Qt::QueuedConnection);
connect(this, SIGNAL(prepareRecording()), this,
SLOT(prepare_recording()));
connect(&audiodevice(), SIGNAL(clientRemoved(Client*)), this, SLOT
(audiodevice_client_removed(Client*)));
connect(&audiodevice(), SIGNAL(started()), this,
SLOT(audiodevice_started()));
@@ -166,6 +166,7 @@
m_transportLocation.set_position(0, audiodevice().get_sample_rate());
m_mode = EDIT;
m_sbx = m_sby = 0;
+ m_currentSampleRate = audiodevice().get_sample_rate();
m_pluginChain = new PluginChain(this, this);
m_fader = m_pluginChain->get_fader();
@@ -930,12 +931,16 @@
// with the correct resampled audio data!
// We need to seek to a different position then the current one,
// else the seek won't happen at all :)
+ if (m_currentSampleRate != audiodevice().get_sample_rate()) {
+ m_currentSampleRate = audiodevice().get_sample_rate();
+
m_diskio->output_rate_changed();
TimeRef location = m_transportLocation;
location.add_frames(1, audiodevice().get_sample_rate());
set_transport_pos(location);
+ }
}
int Song::get_bitdepth( )
@@ -1298,7 +1303,7 @@
m_diskio->prepare_for_seek();
// 'Tell' the diskio it should start a seek action.
- RT_THREAD_EMIT(this,
(void*)m_newTransportLocation.to_frame(audiodevice().get_sample_rate()),
seekStart(uint));
+ RT_THREAD_EMIT(this, NULL, seekStart());
}
void Song::seek_finished()
Index: core/Song.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/Song.h,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -b -r1.64 -r1.65
--- core/Song.h 19 Jul 2007 12:28:42 -0000 1.64
+++ core/Song.h 17 Aug 2007 00:18:30 -0000 1.65
@@ -87,6 +87,9 @@
nframes_t get_working_frame() const {return workingFrame;}
nframes_t get_first_visible_frame() const;
nframes_t get_last_frame() const;
+ const TimeRef& get_transport_location() const {return
m_transportLocation;}
+
+ const TimeRef& get_new_transport_location() const {return
m_newTransportLocation;}
QString get_title() const {return title;}
QString get_artists() const {return artists;}
@@ -185,6 +188,7 @@
int m_hzoom;
int m_sbx;
int m_sby;
+ uint m_currentSampleRate;
bool m_rendering;
bool changed;
bool m_isSnapOn;
@@ -245,7 +249,7 @@
void transportPosSet();
void firstVisibleFrameChanged();
void lastFramePositionChanged();
- void seekStart(uint position);
+ void seekStart();
void snapChanged();
void tempFollowChanged(bool state);
void propertyChanged();
Index: engine/defines.h
===================================================================
RCS file: /sources/traverso/traverso/src/engine/defines.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- engine/defines.h 14 Aug 2007 10:49:55 -0000 1.14
+++ engine/defines.h 17 Aug 2007 00:18:31 -0000 1.15
@@ -49,12 +49,14 @@
};
// Universal samplerate for the frequences 22050, 32000, 44100, 88200, 96000
and 192000 Hz
-static const quint64 UNIVERSAL_SAMPLE_RATE = 28224000;
+static const qint64 UNIVERSAL_SAMPLE_RATE = 28224000;
struct TimeRef {
- TimeRef(){}
- TimeRef(long position) : m_position(position) {}
+ TimeRef() {
+ m_position = 0;
+ }
+ TimeRef(qint64 position) : m_position(position) {}
TimeRef(nframes_t frame, int rate) {
m_position = (UNIVERSAL_SAMPLE_RATE / rate) * frame;
@@ -69,6 +71,7 @@
}
nframes_t to_frame(int rate) {
+ Q_ASSERT(rate);
return nframes_t(m_position / (UNIVERSAL_SAMPLE_RATE / rate));
}
@@ -76,8 +79,46 @@
return left.m_position != right.m_position;
}
+ friend TimeRef operator-(const TimeRef& left, const TimeRef& right) {
+ return TimeRef(left.m_position - right.m_position);
+ }
+
+ friend TimeRef& operator-=(TimeRef& left, const TimeRef& right) {
+ left.m_position -= right.m_position;
+ return left;
+ }
+
+ friend TimeRef operator+(const TimeRef& left, const TimeRef& right) {
+ return TimeRef(left.m_position + right.m_position);
+ }
+
+ friend TimeRef& operator+=(TimeRef& left, const TimeRef& right) {
+ left.m_position += right.m_position;
+ return left;
+ }
+
+ friend int operator<(const TimeRef& left, const TimeRef& right) {
+ return left.m_position < right.m_position;
+ }
+
+ friend int operator>(const TimeRef& left, const TimeRef& right) {
+ return left.m_position > right.m_position;
+ }
+
+ friend int operator<=(const TimeRef& left, const TimeRef& right) {
+ return left.m_position <= right.m_position;
+ }
+
+ friend int operator>=(const TimeRef& left, const TimeRef& right) {
+ return left.m_position >= right.m_position;
+ }
+
+ friend int operator==(const TimeRef& left, const TimeRef& right) {
+ return left.m_position == right.m_position;
+ }
+
private:
- quint64 m_position;
+ qint64 m_position;
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Traverso-commit] traverso/src core/AudioClip.cpp core/AudioClip....,
Remon Sijrier <=