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/Marker.cpp...


From: Remon Sijrier
Subject: [Traverso-commit] traverso/src core/AudioClip.cpp core/Marker.cpp...
Date: Thu, 20 Sep 2007 18:25:15 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Remon Sijrier <r_sijrier>       07/09/20 18:25:15

Modified files:
        src/core       : AudioClip.cpp Marker.cpp Marker.h 
                         ReadSource.cpp Song.cpp TimeLine.cpp Utils.cpp 
                         Utils.h 
        src/traverso/dialogs: MarkerDialog.cpp 
        src/traverso/songcanvas: MarkerView.cpp TimeLineView.cpp 

Log message:
        * more conversions from nframes to TimeRef

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.cpp?cvsroot=traverso&r1=1.133&r2=1.134
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Marker.cpp?cvsroot=traverso&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Marker.h?cvsroot=traverso&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ReadSource.cpp?cvsroot=traverso&r1=1.59&r2=1.60
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Song.cpp?cvsroot=traverso&r1=1.137&r2=1.138
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/TimeLine.cpp?cvsroot=traverso&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Utils.cpp?cvsroot=traverso&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Utils.h?cvsroot=traverso&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/dialogs/MarkerDialog.cpp?cvsroot=traverso&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/songcanvas/MarkerView.cpp?cvsroot=traverso&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/songcanvas/TimeLineView.cpp?cvsroot=traverso&r1=1.45&r2=1.46

Patches:
Index: core/AudioClip.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.cpp,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -b -r1.133 -r1.134
--- core/AudioClip.cpp  17 Sep 2007 18:14:29 -0000      1.133
+++ core/AudioClip.cpp  20 Sep 2007 18:25:14 -0000      1.134
@@ -867,8 +867,6 @@
 
 void AudioClip::calculate_normalization_factor(float targetdB)
 {
-       double maxamp = 0;
-
        float target = dB_to_scale_factor (targetdB);
 
        if (target == 1.0f) {
@@ -878,16 +876,14 @@
                target -= FLT_EPSILON;
        }
 
-       double amp = 
m_peak->get_max_amplitude(m_sourceStartLocation.to_frame(get_rate()), 
m_sourceEndLocation.to_frame(get_rate()));
+       double maxamp = 
m_peak->get_max_amplitude(m_sourceStartLocation.to_frame(get_rate()), 
m_sourceEndLocation.to_frame(get_rate()));
        
-       if (amp == 0.0f) {
+       if (maxamp == 0.0f) {
                printf("AudioClip::normalization: max amplitude == 0\n");
                /* don't even try */
                return;
        }
        
-       maxamp = f_max(amp, maxamp);
-
        if (maxamp == target) {
                printf("AudioClip::normalization: max amplitude == target 
amplitude\n");
                /* we can't do anything useful */

Index: core/Marker.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Marker.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- core/Marker.cpp     9 May 2007 20:36:37 -0000       1.11
+++ core/Marker.cpp     20 Sep 2007 18:25:14 -0000      1.12
@@ -61,7 +61,7 @@
 {
        QDomElement domNode = doc.createElement("Marker");
        
-       domNode.setAttribute("position",  m_when);
+       domNode.setAttribute("position",  m_when.universal_frame());
        domNode.setAttribute("description",  m_description);
        domNode.setAttribute("id",  m_id);
        domNode.setAttribute("performer", m_performer);
@@ -97,7 +97,8 @@
 
        m_description = e.attribute("description", "");
        QString tp = e.attribute("type", "CDTRACK");
-       m_when = e.attribute("position", "0").toUInt();
+       bool ok;
+       m_when = e.attribute("position", "0").toLongLong(&ok);
        m_id = e.attribute("id", "0").toLongLong();
        m_performer = e.attribute("performer", "");
        m_composer = e.attribute("composer", "");
@@ -116,7 +117,7 @@
        return 1;
 }
 
-void Marker::set_when(nframes_t when)
+void Marker::set_when(const TimeRef& when)
 {
        m_when = when;
        emit positionChanged(this);

Index: core/Marker.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/Marker.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- core/Marker.h       9 May 2007 20:36:37 -0000       1.11
+++ core/Marker.h       20 Sep 2007 18:25:15 -0000      1.12
@@ -49,7 +49,7 @@
        QDomNode get_state(QDomDocument doc);
        int set_state(const QDomNode& node);
        
-       void set_when (nframes_t when);
+       void set_when (const TimeRef& when);
        void set_description(const QString &);
        void set_performer(const QString &);
        void set_composer(const QString &);
@@ -61,7 +61,7 @@
        void set_copyprotect(bool);
 
        TimeLine * get_timeline() const {return m_timeline;}
-       nframes_t get_when() const {return m_when;}
+       TimeRef get_when() const {return m_when;}
        QString get_description() const {return m_description;}
        QString get_performer() const {return m_performer;}
        QString get_composer() const {return m_composer;}
@@ -75,7 +75,7 @@
 
 private:
        TimeLine* m_timeline;
-       nframes_t m_when;
+       TimeRef m_when;
        QString m_description,
                m_performer,
                m_composer,

Index: core/ReadSource.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/ReadSource.cpp,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- core/ReadSource.cpp 19 Sep 2007 20:27:46 -0000      1.59
+++ core/ReadSource.cpp 20 Sep 2007 18:25:15 -0000      1.60
@@ -287,6 +287,15 @@
 #endif
        
        int rate = audiodevice().get_sample_rate();
+       
+       // Oh boy, the rate we have to use is the output rate of the resampled 
reader
+       // in case the audioreader is a ResampleAudioReader. Somehow Remon 
thinks it's
+       // better to use TimeRef based read_from() ....
+       ResampleAudioReader* reader = 
dynamic_cast<ResampleAudioReader*>(m_audioReader);
+       if (reader) {
+               rate = reader->get_output_rate();
+       }
+       
        nframes_t result = m_audioReader->read_from(buffer, 
start.to_frame(rate), cnt);
 
 #if defined (profile)

Index: core/Song.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Song.cpp,v
retrieving revision 1.137
retrieving revision 1.138
diff -u -b -r1.137 -r1.138
--- core/Song.cpp       19 Sep 2007 21:33:57 -0000      1.137
+++ core/Song.cpp       20 Sep 2007 18:25:15 -0000      1.138
@@ -376,10 +376,10 @@
        if (spec->isCdExport) {
                QList<Marker*> markers = m_timeline->get_markers();
                if (markers.size() >= 2) {
-                       startlocation = TimeRef(markers.at(0)->get_when(), 
devicerate);
+                       startlocation = markers.at(0)->get_when();
                        PMESG2("  Start marker found at %d", 
startlocation.to_frame(devicerate));
                        // round down to the start of the CD frome (75th of a 
sec)
-                       startlocation = 
TimeRef(cd_to_frame(frame_to_cd(startlocation.to_frame(devicerate), 
m_project->get_rate()), m_project->get_rate()), devicerate);
+                       startlocation = 
cd_to_timeref(timeref_to_cd(startlocation));
                        spec->start_frame = startlocation.to_frame(devicerate);
                } else {
                        PMESG2("  No start marker found");
@@ -820,7 +820,7 @@
 
                                // deactivate the next if-condition (only the 
first one) if you want the
                                // stuff before the first marker to go into the 
pre-gap
-                               if ((nframes_t)(mlist.at(0)->get_when()) != 
(nframes_t)(spec->start_frame)) {
+                               if 
(mlist.at(0)->get_when().to_frame(audiodevice().get_sample_rate()) != 
(spec->start_frame)) {
                                        mlist.append(new Marker(m_timeline, 
spec->start_frame, Marker::TEMP_CDTRACK));
                                }
                                if (mlist.at(0)->get_when() != spec->end_frame) 
{
@@ -838,13 +838,13 @@
 
        // Sort the list according to Marker::get_when() values. This
        // is the correct way to do it according to the Qt docu.
-       QMap<nframes_t, Marker*> markermap;
+       QMap<TimeRef, Marker*> markermap;
        foreach(Marker *marker, mlist) {
                markermap.insert(marker->get_when(), marker);
        }
        mlist = markermap.values();
 
-       nframes_t start = 0;
+       TimeRef start = 0;
        for(int i = 0; i < mlist.size()-1; ++i) {
                Marker* startmarker = mlist.at(i);
                Marker* endmarker = mlist.at(i+1);
@@ -882,10 +882,10 @@
                        //}
                }
                
-               nframes_t length = 
cd_to_frame(frame_to_cd(endmarker->get_when(), m_project->get_rate()), 
m_project->get_rate()) - cd_to_frame(frame_to_cd(startmarker->get_when(), 
m_project->get_rate()), m_project->get_rate());
+               TimeRef length = 
cd_to_timeref(timeref_to_cd(endmarker->get_when())) - 
cd_to_timeref(timeref_to_cd(startmarker->get_when()));
                
-               QString s_start = frame_to_cd(start, m_project->get_rate());
-               QString s_length = frame_to_cd(length, m_project->get_rate());
+               QString s_start = timeref_to_cd(start);
+               QString s_length = timeref_to_cd(length);
 
                output += "  FILE \"" + spec->name + "." + 
spec->extraFormat["filetype"] + "\" " + s_start + " " + s_length + "\n\n";
                start += length;

Index: core/TimeLine.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/TimeLine.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- core/TimeLine.cpp   10 Sep 2007 18:42:49 -0000      1.7
+++ core/TimeLine.cpp   20 Sep 2007 18:25:15 -0000      1.8
@@ -129,7 +129,7 @@
 {
        foreach(Marker* marker, m_markers) {
                if (marker->get_type() == Marker::ENDMARKER) {
-                       pos = TimeRef(marker->get_when(), 
audiodevice().get_sample_rate());
+                       pos = marker->get_when();
                        return true;
                }
        }

Index: core/Utils.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Utils.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- core/Utils.cpp      17 Sep 2007 13:40:35 -0000      1.16
+++ core/Utils.cpp      20 Sep 2007 18:25:15 -0000      1.17
@@ -92,27 +92,6 @@
        return spos;
 }
 
-// Frame to MM:SS:75 (75ths of a second, for CD burning)
-QString frame_to_cd ( nframes_t nframes, int rate )
-{
-       QString spos;
-       long unsigned int remainder;
-       int mins, secs, frames;
-       
-       if (rate != 44100) {
-               nframes = nframes * (44100/rate);
-       }
-
-       mins = nframes / ( 60 * rate );
-       remainder = nframes - ( mins * 60 * rate );
-       secs = remainder / rate;
-       remainder -= secs * rate;
-       frames = remainder * 75 / rate;
-       spos.sprintf ( " %02d:%02d:%02d", mins, secs, frames );
-
-       return spos;
-}
-
 QString frame_to_hms(double nframes, int rate)
 {
        long unsigned int remainder;
@@ -138,18 +117,6 @@
 }
 
 
-nframes_t smpte_to_frame( QString str, int rate )
-{
-       nframes_t out = 0;
-       QStringList lst = str.simplified().split(QRegExp("[;,.:]"), 
QString::SkipEmptyParts);
-
-       if (lst.size() >= 1) out += lst.at(0).toInt() * 60 * rate;
-       if (lst.size() >= 2) out += lst.at(1).toInt() * rate;
-       if (lst.size() >= 3) out += lst.at(2).toInt() * rate / 30;
-
-       return out;
-}
-
 TimeRef msms_to_timeref(QString str)
 {
        TimeRef out = 0;
@@ -162,14 +129,14 @@
        return out;
 }
 
-nframes_t cd_to_frame( QString str, int rate )
+TimeRef cd_to_timeref(QString str)
 {
-       nframes_t out = 0;
+       TimeRef out = 0;
        QStringList lst = str.simplified().split(QRegExp("[;,.:]"), 
QString::SkipEmptyParts);
 
-       if (lst.size() >= 1) out += lst.at(0).toInt() * 60 * rate;
-       if (lst.size() >= 2) out += lst.at(1).toInt() * rate;
-       if (lst.size() >= 3) out += lst.at(2).toInt() * rate / 75;
+       if (lst.size() >= 1) out += lst.at(0).toInt() * 
ONE_MINUTE_UNIVERSAL_SAMPLE_RATE;
+       if (lst.size() >= 2) out += lst.at(1).toInt() * UNIVERSAL_SAMPLE_RATE;
+       if (lst.size() >= 3) out += lst.at(2).toInt() * UNIVERSAL_SAMPLE_RATE / 
75;
 
        return out;
 }
@@ -273,6 +240,24 @@
        return spos;
 }
 
+// Frame to MM:SS:75 (75ths of a second, for CD burning)
+QString timeref_to_cd (const TimeRef& ref)
+{
+       QString spos;
+       long unsigned int remainder;
+       int mins, secs, frames;
+       
+       qint64 universalframe = ref.universal_frame();
+       
+       mins = universalframe / ( ONE_MINUTE_UNIVERSAL_SAMPLE_RATE );
+       remainder = universalframe - ( mins * ONE_MINUTE_UNIVERSAL_SAMPLE_RATE 
);
+       secs = remainder / UNIVERSAL_SAMPLE_RATE;
+       remainder -= secs * UNIVERSAL_SAMPLE_RATE;
+       frames = remainder * 75 / UNIVERSAL_SAMPLE_RATE;
+       spos.sprintf ( " %02d:%02d:%02d", mins, secs, frames );
+
+       return spos;
+}
 
 QString timeref_to_text(const TimeRef & ref, int scalefactor)
 {

Index: core/Utils.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/Utils.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- core/Utils.h        10 Sep 2007 18:42:49 -0000      1.12
+++ core/Utils.h        20 Sep 2007 18:25:15 -0000      1.13
@@ -34,7 +34,6 @@
 QString frame_to_smpte(nframes_t nframes, int rate);
 QString frame_to_ms_3(nframes_t nframes, int rate);
 QString frame_to_ms_2(nframes_t nframes, int rate);
-QString frame_to_cd(nframes_t nframes, int rate);
 QString frame_to_hms(double nframes, int rate);
 QString frame_to_ms(double nframes, int rate);
 
@@ -42,10 +41,10 @@
 QString timeref_to_ms_2 (const TimeRef& ref);
 QString timeref_to_ms_3 (const TimeRef& ref);
 QString timeref_to_text(const TimeRef& ref, int scalefactor);
+QString timeref_to_cd(const TimeRef& ref);
 
-nframes_t smpte_to_frame(QString str, int rate);
 TimeRef msms_to_timeref(QString str);
-nframes_t cd_to_frame(QString str, int rate);
+TimeRef cd_to_timeref(QString str);
 QString coefficient_to_dbstring(float coeff);
 QDateTime extract_date_time(qint64 id);
 

Index: traverso/dialogs/MarkerDialog.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/dialogs/MarkerDialog.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- traverso/dialogs/MarkerDialog.cpp   21 May 2007 08:49:46 -0000      1.11
+++ traverso/dialogs/MarkerDialog.cpp   20 Sep 2007 18:25:15 -0000      1.12
@@ -147,7 +147,7 @@
                
        foreach(Marker* marker, tl->get_markers()) {
                QString name = marker->get_description();
-               QString pos = frame_to_cd(marker->get_when(), 
m_project->get_rate());
+               QString pos = timeref_to_cd(marker->get_when());
 
                QTreeWidgetItem* item = new QTreeWidgetItem(markersTreeWidget);
                item->setText(0, QString("%1 %2").arg(index, 2, 10, 
QLatin1Char('0')).arg(song->get_title()));
@@ -174,7 +174,7 @@
 
        if (previous) {
                Marker *marker = get_marker(previous->data(0, 
Qt::UserRole).toLongLong());
-               marker->set_when(cd_to_frame(lineEditPosition->text(), 
m_project->get_rate()));
+               marker->set_when(cd_to_timeref(lineEditPosition->text()));
                marker->set_description(lineEditTitle->text());
                marker->set_performer(lineEditPerformer->text());
                marker->set_composer(lineEditComposer->text());
@@ -186,7 +186,7 @@
                marker->set_copyprotect(checkBoxCopy->isChecked());
        }
 
-       lineEditPosition->setText(frame_to_cd(m_marker->get_when(), 
m_project->get_rate()));
+       lineEditPosition->setText(timeref_to_cd(m_marker->get_when()));
        lineEditTitle->setText(m_marker->get_description());
        lineEditPerformer->setText(m_marker->get_performer());
        lineEditComposer->setText(m_marker->get_composer());
@@ -221,7 +221,8 @@
        }
 
        item->setText(1, s);
-       m_marker->set_when(cd_to_frame(s, m_project->get_rate()));
+       TimeRef location = cd_to_timeref(s);
+       m_marker->set_when(location);
        markersTreeWidget->sortItems(1, Qt::AscendingOrder);
 }
 
@@ -514,7 +515,7 @@
                
        foreach(Marker* marker, tl->get_markers()) {
                QString name = marker->get_description();
-               QString pos = frame_to_cd(marker->get_when(), 
m_project->get_rate());
+               QString pos = timeref_to_cd(marker->get_when());
 
                out << "      <tr><td>" << pos << "</td>\n        <td>" << name 
<< "</td></tr>\n";
        }       

Index: traverso/songcanvas/MarkerView.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/songcanvas/MarkerView.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- traverso/songcanvas/MarkerView.cpp  10 Sep 2007 18:44:16 -0000      1.22
+++ traverso/songcanvas/MarkerView.cpp  20 Sep 2007 18:25:15 -0000      1.23
@@ -106,7 +106,7 @@
 void MarkerView::update_position()
 {
        // markerwidth / 2 == center of markerview !
-       setPos( (long)(m_marker->get_when() / m_sv->scalefactor) - (m_width / 
2), 0);
+       setPos( (long)(m_marker->get_when() / m_sv->timeref_scalefactor) - 
(m_width / 2), 0);
 }
 
 int MarkerView::position()

Index: traverso/songcanvas/TimeLineView.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/songcanvas/TimeLineView.cpp,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- traverso/songcanvas/TimeLineView.cpp        10 Sep 2007 19:22:52 -0000      
1.45
+++ traverso/songcanvas/TimeLineView.cpp        20 Sep 2007 18:25:15 -0000      
1.46
@@ -61,7 +61,7 @@
        Q_CLASSINFO("move_right", tr("Move right"))
        
 public:
-       DragMarker(MarkerView* mview, double scalefactor, const QString& des);
+       DragMarker(MarkerView* mview, qint64 scalefactor, const QString& des);
 
        int prepare_actions();
        int do_action();
@@ -73,11 +73,11 @@
 
 private :
        Marker*         m_marker;
-       nframes_t       m_origWhen;
-       nframes_t       m_newWhen;
+       TimeRef         m_origWhen;
+       TimeRef         m_newWhen;
        struct Data {
                MarkerView*     view;
-               double          scalefactor;
+               qint64          scalefactor;
                bool            bypassjog;
                int             jogBypassPos;
        };
@@ -92,7 +92,7 @@
 #include "TimeLineView.moc"
 
        
-DragMarker::DragMarker(MarkerView* mview, double scalefactor, const QString& 
des)
+DragMarker::DragMarker(MarkerView* mview, qint64 scalefactor, const QString& 
des)
        : Command(mview->get_marker(), des)
 {
        d = new Data;
@@ -147,7 +147,7 @@
 {
        d->bypassjog = true;
        // Move 1 pixel to the left
-       long newpos = m_newWhen - (uint) ( 1 * d->scalefactor);
+       TimeRef newpos = TimeRef(m_newWhen - d->scalefactor);
        if (newpos < 0) {
                newpos = 0;
        }
@@ -159,7 +159,7 @@
 {
        d->bypassjog = true;
        // Move 1 pixel to the right
-       m_newWhen = m_newWhen + (uint) ( 1 * d->scalefactor);
+       m_newWhen = m_newWhen + d->scalefactor;
        do_action();
 }
 
@@ -186,7 +186,7 @@
                newpos = 0;
        }
        
-       m_newWhen = newpos / 640;
+       m_newWhen = qint64(newpos / 640);
        d->view->set_position(int(m_newWhen / d->scalefactor));
        
        d->view->get_songview()->update_shuttle_factor();
@@ -297,7 +297,8 @@
 
        // minor is double so they line up right with the majors,
        // despite not always being an even number of frames
-       double minor = major/10.0;
+       // @Ben : is still still the same when using TimeRef based calculations?
+       TimeRef minor = qint64(major/10);
 
        TimeRef firstLocation = xstart * m_sv->timeref_scalefactor;
        TimeRef lastLocation = xstart * m_sv->timeref_scalefactor + pixelcount 
* m_sv->timeref_scalefactor;
@@ -314,7 +315,7 @@
        
        // Draw major ticks
        for (TimeRef location = firstlocactiondividedbymajorsquare; location < 
lastLocation; location += major) {
-               int x = location/m_sv->timeref_scalefactor - xstartoffset;
+               int x = int(location/m_sv->timeref_scalefactor - xstartoffset);
                painter->drawLine(x, height - 13, x, height - 1);
                if (paintText) {
                        painter->drawText(x + 4, height - 8, 
timeref_to_text(location, m_sv->timeref_scalefactor));
@@ -406,7 +407,7 @@
        
update_softselected_marker(QPoint(cpointer().on_first_input_event_scene_x(), 
cpointer().on_first_input_event_scene_y()));
 
        if (m_blinkingMarker) {
-               
m_sv->get_song()->set_transport_pos(m_blinkingMarker->get_marker()->get_when() 
* 640);
+               
m_sv->get_song()->set_transport_pos(m_blinkingMarker->get_marker()->get_when());
                return 0;
        }
 




reply via email to

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