[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Traverso-commit] traverso/src commands/PCommand.cpp commands/PCo...
From: |
Remon Sijrier |
Subject: |
[Traverso-commit] traverso/src commands/PCommand.cpp commands/PCo... |
Date: |
Mon, 09 Mar 2009 19:44:07 +0000 |
CVSROOT: /sources/traverso
Module name: traverso
Changes by: Remon Sijrier <r_sijrier> 09/03/09 19:44:06
Modified files:
src/commands : PCommand.cpp PCommand.h
src/core : AudioClip.cpp AudioClip.h Peak.cpp
Log message:
* Make Normalization un/redoable also
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/commands/PCommand.cpp?cvsroot=traverso&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/traverso/src/commands/PCommand.h?cvsroot=traverso&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.cpp?cvsroot=traverso&r1=1.169&r2=1.170
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AudioClip.h?cvsroot=traverso&r1=1.76&r2=1.77
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/Peak.cpp?cvsroot=traverso&r1=1.87&r2=1.88
Patches:
Index: commands/PCommand.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/commands/PCommand.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- commands/PCommand.cpp 11 Dec 2007 17:30:10 -0000 1.7
+++ commands/PCommand.cpp 9 Mar 2009 19:44:06 -0000 1.8
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2005-2006 Remon Sijrier
+Copyright (C) 2005-2009 Remon Sijrier
This file is part of Traverso
@@ -17,7 +17,6 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: PCommand.cpp,v 1.7 2007/12/11 17:30:10 r_sijrier Exp $
*/
#include "PCommand.h"
@@ -28,6 +27,27 @@
// in case we run with memory leak detection enabled!
#include "Debugger.h"
+/** \class PCommand
+ * \brief A Command class that can be used to create historable actions
+
+ Use this class to create actions that basically involve calling one
+ function to set and restore a value.
+
+ E.g. setting and resetting the gain of an object can be done like this:
+
+ \code
+ PCommand(SomeObject, "do_something", newvalue, oldvalue, tr("MyObject:
Did something"));
+ \endcode
+
+ where SomeObject is a pointer to a QObject derived class, and
"do_something" is a function
+ that accepts a value of the type of newvalue/oldvalue. "do_something"
needs to be declared
+ as a public slot!
+
+ \n
+ Supported types are: TimeRef, double and float.
+ *
+ */
+
PCommand::PCommand(ContextItem* item, const char* slot, const QString& des)
: Command(item, des)
@@ -65,6 +85,16 @@
}
}
+ // covers both the float and double types!
+ if (m_doValue.type() == QVariant::Double) {
+ bool ok;
+ if (QMetaObject::invokeMethod(m_contextitem,
m_slot, Qt::DirectConnection, Q_ARG(float, m_doValue.toDouble(&ok)))) {
+ return 1;
+ } else if
(QMetaObject::invokeMethod(m_contextitem, m_slot, Qt::DirectConnection,
Q_ARG(double, m_doValue.toDouble(&ok)))) {
+ return 1;
+ }
+ }
+
return -1;
}
@@ -81,9 +111,20 @@
}
}
+ // covers both the float and double types!
+ if (m_undoValue.type() == QVariant::Double) {
+ bool ok;
+ if (QMetaObject::invokeMethod(m_contextitem,
m_slot, Qt::DirectConnection, Q_ARG(float, m_undoValue.toDouble(&ok)))) {
+ return 1;
+ } else if
(QMetaObject::invokeMethod(m_contextitem, m_slot, Qt::DirectConnection,
Q_ARG(double, m_undoValue.toDouble(&ok)))) {
+ return 1;
+ }
+ }
+
return -1;
}
+
return QMetaObject::invokeMethod(m_contextitem, m_slot);
}
Index: commands/PCommand.h
===================================================================
RCS file: /sources/traverso/traverso/src/commands/PCommand.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- commands/PCommand.h 11 Dec 2007 17:30:10 -0000 1.4
+++ commands/PCommand.h 9 Mar 2009 19:44:06 -0000 1.5
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2005-2006 Remon Sijrier
+ Copyright (C) 2005-2009 Remon Sijrier
This file is part of Traverso
@@ -17,7 +17,6 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- $Id: PCommand.h,v 1.4 2007/12/11 17:30:10 r_sijrier Exp $
*/
#ifndef PCOMMAND_H
Index: core/AudioClip.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.cpp,v
retrieving revision 1.169
retrieving revision 1.170
diff -u -b -r1.169 -r1.170
--- core/AudioClip.cpp 7 Mar 2009 16:36:18 -0000 1.169
+++ core/AudioClip.cpp 9 Mar 2009 19:44:06 -0000 1.170
@@ -50,6 +50,7 @@
#include <Config.h>
#include "PluginChain.h"
#include "GainEnvelope.h"
+#include "InputEngine.h"
#include "AbstractAudioReader.h"
@@ -898,22 +899,22 @@
Command * AudioClip::normalize( )
{
bool ok;
+ float normfactor;
double d = QInputDialog::getDouble(0, tr("Normalization"),
tr("Set Normalization level:"),
0.0, -120, 0, 1, &ok);
if (ok) {
- calculate_normalization_factor(d);
+ normfactor = calculate_normalization_factor(d);
}
- return (Command*) 0;
-}
+ if (!ok || (normfactor == get_gain())) {
+ return ie().failure();
+ }
-Command * AudioClip::denormalize( )
-{
- set_gain(1.0);
- return (Command*) 0;
+ return new PCommand(this, "set_gain", normfactor, get_gain(),
tr("AudioClip: Normalize"));
}
-void AudioClip::calculate_normalization_factor(float targetdB)
+
+float AudioClip::calculate_normalization_factor(float targetdB)
{
float target = dB_to_scale_factor (targetdB);
@@ -929,17 +930,17 @@
if (maxamp == 0.0f) {
printf("AudioClip::normalization: max amplitude == 0\n");
/* don't even try */
- return;
+ return get_gain();
}
if (maxamp == target) {
printf("AudioClip::normalization: max amplitude == target
amplitude\n");
/* we can't do anything useful */
- return;
+ return get_gain();
}
/* compute scale factor */
- set_gain(target/maxamp);
+ return float(target/maxamp);
}
FadeCurve * AudioClip::get_fade_in( ) const
Index: core/AudioClip.h
===================================================================
RCS file: /sources/traverso/traverso/src/core/AudioClip.h,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -b -r1.76 -r1.77
--- core/AudioClip.h 17 Jan 2009 18:18:02 -0000 1.76
+++ core/AudioClip.h 9 Mar 2009 19:44:06 -0000 1.77
@@ -50,7 +50,6 @@
Q_CLASSINFO("reset_fade_out", tr("Out: Remove"))
Q_CLASSINFO("reset_fade_both", tr("Both: Remove"))
Q_CLASSINFO("normalize", tr("Normalize"))
- Q_CLASSINFO("denormalize", tr("Normalize: Reset"))
Q_CLASSINFO("lock", tr("Lock"))
public:
@@ -157,7 +156,7 @@
void process_capture(nframes_t nframes);
- void calculate_normalization_factor(float targetdB = 0.0);
+ float calculate_normalization_factor(float targetdB = 0.0);
friend class ResourcesManager;
@@ -187,7 +186,6 @@
Command* reset_fade_out();
Command* reset_fade_both();
Command* normalize();
- Command* denormalize();
Command* lock();
private slots:
Index: core/Peak.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/Peak.cpp,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -b -r1.87 -r1.88
--- core/Peak.cpp 23 Feb 2009 20:14:59 -0000 1.87
+++ core/Peak.cpp 9 Mar 2009 19:44:06 -0000 1.88
@@ -737,7 +737,7 @@
int read = data->file.read((char*)readbuffer,
sizeof(audio_sample_t) * count) / sizeof(audio_sample_t);
if (read != (int)count) {
- printf("could only read %d, %d requested\n", read,
count);
+ printf("Peak::get_max_amplitude: could only read %d,
%d requested\n", read, count);
}
maxamp = Mixer::compute_peak(readbuffer, read, maxamp);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Traverso-commit] traverso/src commands/PCommand.cpp commands/PCo...,
Remon Sijrier <=