[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Traverso-commit] traverso/src/common Utils.cpp Utils.h defines.h
From: |
Remon Sijrier |
Subject: |
[Traverso-commit] traverso/src/common Utils.cpp Utils.h defines.h |
Date: |
Sat, 20 Oct 2007 12:45:09 +0000 |
CVSROOT: /sources/traverso
Module name: traverso
Changes by: Remon Sijrier <r_sijrier> 07/10/20 12:45:09
Added files:
src/common : Utils.cpp Utils.h defines.h
Log message:
* move files that don't belong too any lib but are used by all to a
common dir
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/common/Utils.cpp?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/common/Utils.h?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/common/defines.h?cvsroot=traverso&rev=1.1
Patches:
Index: Utils.cpp
===================================================================
RCS file: Utils.cpp
diff -N Utils.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Utils.cpp 20 Oct 2007 12:45:08 -0000 1.1
@@ -0,0 +1,198 @@
+/*
+ Copyright (C) 2005-2007 Remon Sijrier
+
+ This file is part of Traverso
+
+ Traverso is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#include "Utils.h"
+#include "Mixer.h"
+
+#include <QString>
+#include <QStringList>
+#include <QDateTime>
+#include <QPixmapCache>
+#include <QRegExp>
+#include <QLocale>
+#include <QChar>
+
+
+TimeRef msms_to_timeref(QString str)
+{
+ TimeRef out;
+ QStringList lst = str.simplified().split(QRegExp("[;,.:]"),
QString::SkipEmptyParts);
+
+ if (lst.size() >= 1) out += TimeRef(lst.at(0).toInt() *
ONE_MINUTE_UNIVERSAL_SAMPLE_RATE);
+ if (lst.size() >= 2) out += TimeRef(lst.at(1).toInt() *
UNIVERSAL_SAMPLE_RATE);
+ if (lst.size() >= 3) out += TimeRef(lst.at(2).toInt() *
UNIVERSAL_SAMPLE_RATE / 1000);
+
+ return out;
+}
+
+TimeRef cd_to_timeref(QString str)
+{
+ TimeRef out;
+ QStringList lst = str.simplified().split(QRegExp("[;,.:]"),
QString::SkipEmptyParts);
+
+ if (lst.size() >= 1) out += TimeRef(lst.at(0).toInt() *
ONE_MINUTE_UNIVERSAL_SAMPLE_RATE);
+ if (lst.size() >= 2) out += TimeRef(lst.at(1).toInt() *
UNIVERSAL_SAMPLE_RATE);
+ if (lst.size() >= 3) out += TimeRef(lst.at(2).toInt() *
UNIVERSAL_SAMPLE_RATE / 75);
+
+ return out;
+}
+
+QString coefficient_to_dbstring ( float coeff )
+{
+ float db = coefficient_to_dB ( coeff );
+
+ QString gainIndB;
+
+ if ( db < -99 )
+ gainIndB = "- INF";
+ else if ( db < 0 )
+ gainIndB = "- " + QByteArray::number ( ( -1 * db ), 'f', 1 ) +
" dB";
+ else
+ gainIndB = "+ " + QByteArray::number ( db, 'f', 1 ) + " dB";
+
+ return gainIndB;
+}
+
+qint64 create_id( )
+{
+ int r = rand();
+ QDateTime time = QDateTime::currentDateTime();
+ uint timeValue = time.toTime_t();
+ qint64 id = timeValue;
+ id *= 1000000000;
+ id += r;
+
+ return id;
+}
+
+QDateTime extract_date_time(qint64 id)
+{
+ QDateTime time;
+ time.setTime_t(id / 1000000000);
+ return time;
+}
+
+QPixmap find_pixmap ( const QString & pixname )
+{
+ QPixmap pixmap;
+
+ if ( ! QPixmapCache::find ( pixname, pixmap ) )
+ {
+ pixmap = QPixmap ( pixname );
+ QPixmapCache::insert ( pixname, pixmap );
+ }
+
+ return pixmap;
+}
+
+QString timeref_to_hms(const TimeRef& ref)
+{
+ qint64 remainder;
+ int hours, mins, secs;
+
+ qint64 universalframe = ref.universal_frame();
+
+ hours = (int) (universalframe / ONE_HOUR_UNIVERSAL_SAMPLE_RATE);
+ remainder = (long unsigned int) (universalframe - (hours *
ONE_HOUR_UNIVERSAL_SAMPLE_RATE));
+ mins = (int) (remainder / ( ONE_MINUTE_UNIVERSAL_SAMPLE_RATE ));
+ remainder -= mins * ONE_MINUTE_UNIVERSAL_SAMPLE_RATE;
+ secs = (int) (remainder / UNIVERSAL_SAMPLE_RATE);
+ return QString().sprintf("%02d:%02d:%02d", hours, mins, secs);
+}
+
+QString timeref_to_ms(const TimeRef& ref)
+{
+ long unsigned int remainder;
+ int mins, secs;
+
+ qint64 universalframe = ref.universal_frame();
+
+ mins = (int) (universalframe / ( ONE_MINUTE_UNIVERSAL_SAMPLE_RATE ));
+ remainder = (long unsigned int) (universalframe - (mins *
ONE_MINUTE_UNIVERSAL_SAMPLE_RATE));
+ secs = (int) (remainder / UNIVERSAL_SAMPLE_RATE);
+ return QString().sprintf("%02d:%02d", mins, secs);
+}
+
+// TimeRef to MM:SS.99 (hundredths)
+QString timeref_to_ms_2 (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 * 100 / UNIVERSAL_SAMPLE_RATE;
+ spos.sprintf ( " %02d:%02d%c%02d", mins, secs,
QLocale::system().decimalPoint().toAscii(), frames );
+
+ return spos;
+}
+
+// TimeRef to MM:SS.999 (ms)
+QString timeref_to_ms_3(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 * 1000 / UNIVERSAL_SAMPLE_RATE;
+ spos.sprintf ( " %02d:%02d%c%03d", mins, secs,
QLocale::system().decimalPoint().toAscii(), frames );
+
+ 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)
+{
+ if (scalefactor >= 512*640) {
+ return timeref_to_ms_2(ref);
+ } else {
+ return timeref_to_ms_3(ref);
+ }
+}
Index: Utils.h
===================================================================
RCS file: Utils.h
diff -N Utils.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Utils.h 20 Oct 2007 12:45:09 -0000 1.1
@@ -0,0 +1,54 @@
+/*
+ Copyright (C) 2005-2007 Remon Sijrier
+
+ This file is part of Traverso
+
+ Traverso is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#ifndef UTILS_H
+#define UTILS_H
+
+#include "defines.h"
+#include <QPixmap>
+#include <QDateTime>
+
+#define QS_C(x) x.toAscii().data()
+
+class QString;
+
+QString timeref_to_hms(const TimeRef& ref);
+QString timeref_to_ms(const TimeRef& ref);
+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);
+
+TimeRef msms_to_timeref(QString str);
+TimeRef cd_to_timeref(QString str);
+QString coefficient_to_dbstring(float coeff);
+QDateTime extract_date_time(qint64 id);
+
+qint64 create_id();
+
+static inline unsigned int is_power_of_two (unsigned int n)
+{
+ return !(n & (n - 1));
+}
+
+QPixmap find_pixmap(const QString& pixname);
+
+#endif
Index: defines.h
===================================================================
RCS file: defines.h
diff -N defines.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ defines.h 20 Oct 2007 12:45:09 -0000 1.1
@@ -0,0 +1,393 @@
+#ifndef TRAVERSO_TYPES_H
+#define TRAVERSO_TYPES_H
+
+#include <inttypes.h>
+#include <QtGlobal>
+#include <QMetaType>
+#include "FastDelegate.h"
+
+// Implementation for atomic int get/set from glibc's atomic.h/c
+// to get rid of the glib dependency!
+// Arches that need memory bariers: ppc (which we support)
+// and sparc, alpha, ia64 which we do not support ??
+
+#if defined(__ppc__) || defined(__powerpc__) || defined(__PPC__)
+
+# define T_ATOMIC_MEMORY_BARRIER __asm__ ("sync" : : : "memory")
+
+static inline int t_atomic_int_get (volatile int *atomic)
+{
+ T_ATOMIC_MEMORY_BARRIER;
+ return *atomic;
+}
+
+static inline void t_atomic_int_set (volatile int *atomic, int newval)
+{
+ *atomic = newval;
+ T_ATOMIC_MEMORY_BARRIER;
+}
+
+#else
+
+# define t_atomic_int_get(atomic) (*(atomic))
+# define t_atomic_int_set(atomic, newval) ((void) (*(atomic) = (newval)))
+
+#endif // ENDIF __ppc__
+
+
+using namespace fastdelegate;
+
+/**
+ * Type used to represent sample frame counts.
+ */
+typedef uint32_t nframes_t;
+
+enum {
+ TransportStopped = 0,
+ TransportRolling = 1,
+ TransportLooping = 2,
+ TransportStarting = 3
+};
+
+// Universal samplerate for the frequences 22050, 32000, 44100, 88200, 96000
and 192000 Hz
+static const qint64 UNIVERSAL_SAMPLE_RATE = 28224000;
+static const qint64 ONE_HOUR_UNIVERSAL_SAMPLE_RATE = 101606400000LL;
+static const qint64 ONE_MINUTE_UNIVERSAL_SAMPLE_RATE = 1693440000LL;
+
+struct TimeRef {
+
+ TimeRef() {
+ m_position = 0;
+ }
+ explicit TimeRef(qint64 position) : m_position(position) {}
+ explicit TimeRef(double position) : m_position(qint64(position)) {}
+
+ TimeRef(nframes_t frame, int rate) {
+ m_position = (UNIVERSAL_SAMPLE_RATE / rate) * frame;
+ }
+
+ void add_frames(nframes_t frames, int rate) {
+ m_position += ((UNIVERSAL_SAMPLE_RATE / rate) * frames);
+ }
+
+ nframes_t to_frame(int rate) {
+ Q_ASSERT(rate);
+ return nframes_t(m_position / (UNIVERSAL_SAMPLE_RATE / rate));
+ }
+
+ qint64 universal_frame() const {return m_position;}
+
+ TimeRef operator =(qint64 value) {
+ TimeRef ref(value);
+ return ref;
+ }
+
+ friend int operator!=(const TimeRef& left, const TimeRef& right) {
+ 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-(const TimeRef& left, qint64 right) {
+ TimeRef location(left.m_position - right);
+ return location;
+ }
+
+ friend TimeRef& operator-=(TimeRef& left, const TimeRef& right) {
+ left.m_position -= right.m_position;
+ return left;
+ }
+
+ friend TimeRef& operator-=(TimeRef& left, qint64 right) {
+ left.m_position -= right;
+ return left;
+ }
+
+ friend TimeRef operator+(const TimeRef& left, const TimeRef& right) {
+ return TimeRef(left.m_position + right.m_position);
+ }
+
+ friend TimeRef operator+(const TimeRef& left, qint64 right) {
+ TimeRef location(left.m_position + right);
+ return location;
+ }
+
+ friend TimeRef& operator+=(TimeRef& left, const TimeRef& right) {
+ left.m_position += right.m_position;
+ return left;
+ }
+
+ friend qreal operator/(const TimeRef& left, const qint64 right) {
+ return (qreal)left.m_position / right;
+ }
+
+ friend TimeRef operator/(const TimeRef& left, const TimeRef& right) {
+ Q_ASSERT(right.m_position != 0);
+ TimeRef location(left.m_position / right.m_position);
+ return location;
+ }
+
+ friend TimeRef operator*(const qint64 left, TimeRef& right) {
+ TimeRef location(left * right.m_position);
+ return location;
+ }
+
+ friend TimeRef operator*(const TimeRef& left, TimeRef& right) {
+ TimeRef location(left.m_position * right.m_position);
+ return location;
+ }
+
+ friend int operator<(const TimeRef& left, const TimeRef& right) {
+ return left.m_position < right.m_position;
+ }
+
+ friend int operator<(const TimeRef& left, qint64 right) {
+ return left.m_position < right;
+ }
+
+ friend int operator>(const TimeRef& left, const TimeRef& right) {
+ return left.m_position > right.m_position;
+ }
+
+ friend int operator>(const TimeRef& left, qint64 right) {
+ return left.m_position > right;
+ }
+
+ 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, qint64 right) {
+ return left.m_position == right;
+ }
+
+private:
+ qint64 m_position;
+};
+
+Q_DECLARE_METATYPE(TimeRef);
+
+typedef struct {
+ int tranport;
+ bool isSlave;
+ bool realtime;
+ TimeRef location;
+} transport_state_t;
+
+/**
+ * Type used to represent the value of free running
+ * monotonic clock with units of microseconds.
+ */
+typedef double trav_time_t;
+
+typedef unsigned long channel_t;
+
+typedef float audio_sample_t;
+typedef unsigned char peak_data_t;
+// typedef short peak_data_t;
+
+
+typedef FastDelegate1<nframes_t, int> ProcessCallback;
+typedef FastDelegate0<int> RunCycleCallback;
+typedef FastDelegate1<transport_state_t, int> TransportControlCallback;
+
+
+/**
+ * Used for the type argument of jack_port_register() for default
+ * audio ports.
+ */
+#define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
+
+
+/**
+ * A port has a set of flags that are formed by AND-ing together the
+ * desired values from the list below. The flags "PortIsInput" and
+ * "PortIsOutput" are mutually exclusive and it is an error to use
+ * them both.
+ */
+enum PortFlags {
+
+ /**
+ * if PortIsInput is set, then the port can receive
+ * data.
+ */
+ PortIsInput = 0x1,
+
+ /**
+ * if PortIsOutput is set, then data can be read from
+ * the port.
+ */
+ PortIsOutput = 0x2,
+
+ /**
+ * if PortIsPhysical is set, then the port corresponds
+ * to some kind of physical I/O connector.
+ */
+ PortIsPhysical = 0x4,
+
+ /**
+ * if PortCanMonitor is set, then a call to
+ * jack_port_request_monitor() makes sense.
+ *
+ * Precisely what this means is dependent on the client. A typical
+ * result of it being called with TRUE as the second argument is
+ * that data that would be available from an output port (with
+ * PortIsPhysical set) is sent to a physical output connector
+ * as well, so that it can be heard/seen/whatever.
+ *
+ * Clients that do not control physical interfaces
+ * should never create ports with this bit set.
+ */
+ PortCanMonitor = 0x8,
+
+ /**
+ * PortIsTerminal means:
+ *
+ * for an input port: the data received by the port
+ * will not be passed on or made
+ * available at any other port
+ *
+ * for an output port: the data available at the port
+ * does not originate from any other port
+ *
+ * Audio synthesizers, I/O hardware interface clients, HDR
+ * systems are examples of clients that would set this flag for
+ * their ports.
+ */
+ PortIsTerminal = 0x10
+};
+
+
+#if defined(_MSC_VER) || defined(__MINGW32__)
+# include <time.h>
+#ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */
+#define _TIMEVAL_DEFINED
+struct timeval {
+ long tv_sec;
+ long tv_usec;
+};
+#endif /* _TIMEVAL_DEFINED */
+#else
+# include <sys/time.h>
+#endif
+
+
+#if defined(_MSC_VER) || defined(__MINGW32__)
+
+#include <Windows.h>
+
+static inline int gettimeofday(struct timeval* tp, void* tzp) {
+ DWORD t;
+ t = timeGetTime();
+ tp->tv_sec = t / 1000;
+ tp->tv_usec = t % 1000;
+ /* 0 indicates that the call succeeded. */
+ return 0;
+}
+
+typedef uint8_t u_int8_t;
+
+#endif
+
+static inline trav_time_t get_microseconds()
+{
+ struct timeval now;
+ gettimeofday(&now, 0);
+ trav_time_t time = (now.tv_sec * 1000000.0 + now.tv_usec);
+ return time;
+}
+
+#if defined (RELAYTOOL_PRESENT)
+
+#define RELAYTOOL_JACK \
+ extern int libjack_is_present;\
+ extern int libjack_symbol_is_present(char *s);
+
+#define RELAYTOOL_WAVPACK \
+ extern int libwavpack_is_present;\
+ extern int libwavpack_symbol_is_present(char *s);
+
+#define RELAYTOOL_FLAC \
+ extern int libFLAC_is_present;\
+ extern int libFLAC_symbol_is_present(char *s);
+
+
+#define RELAYTOOL_MAD \
+ extern int libmad_is_present;\
+ extern int libmad_symbol_is_present(char *s);
+
+#define RELAYTOOL_OGG \
+ extern int libogg_is_present;\
+ extern int libogg_symbol_is_present(char *s);
+
+#define RELAYTOOL_VORBIS \
+ extern int libvorbis_is_present;\
+ extern int libvorbis_symbol_is_present(char *s);
+
+#define RELAYTOOL_VORBISFILE \
+ extern int libvorbisfile_is_present;\
+ extern int libvorbisfile_symbol_is_present(char *s);
+
+#define RELAYTOOL_VORBISENC \
+ extern int libvorbisenc_is_present;\
+ extern int libvorbisenc_symbol_is_present(char *s);
+
+
+#else
+
+
+#define RELAYTOOL_JACK \
+ static const int libjack_is_present=1;\
+ static int __attribute__((unused)) libjack_symbol_is_present(char *) {
return 1; }
+
+#define RELAYTOOL_WAVPACK \
+ static const int libwavpack_is_present=1;\
+ static int __attribute__((unused)) libwavpack_symbol_is_present(char *)
{ return 1; }
+
+#define RELAYTOOL_FLAC \
+ static const int libFLAC_is_present=1;\
+ static int __attribute__((unused)) libFLAC_symbol_is_present(char *) {
return 1; }
+
+#define RELAYTOOL_MAD \
+ static const int libmad_is_present=1;\
+ static int __attribute__((unused)) libmad_symbol_is_present(char *) {
return 1; }
+
+#define RELAYTOOL_OGG \
+ static const int libogg_is_present=1;\
+ static int __attribute__((unused)) libogg_symbol_is_present(char *) {
return 1; }
+
+#define RELAYTOOL_VORBIS \
+ static const int libvorbis_is_present=1;\
+ static int __attribute__((unused)) libvorbis_symbol_is_present(char *)
{ return 1; }
+
+#define RELAYTOOL_VORBISFILE \
+ static const int libvorbisfile_is_present=1;\
+ static int __attribute__((unused)) libvorbisfile_symbol_is_present(char
*) { return 1; }
+
+#define RELAYTOOL_VORBISENC \
+ static const int libvorbisenc_is_present=1;\
+ static int __attribute__((unused)) libvorbisenc_symbol_is_present(char
*) { return 1; }
+
+#define RELAYTOOL_MP3LAME \
+ static const int libmp3lame_is_present=1;\
+ static int __attribute__((unused)) libmp3lame_symbol_is_present(char *)
{ return 1; }
+
+#endif // endif RELAYTOOL_PRESENT
+
+
+#define PROFILE_START trav_time_t starttime = get_microseconds();
+#define PROFILE_END(args...) int processtime = (int) (get_microseconds() -
starttime);printf("Process time for %s: %d useconds\n\n", args, processtime);
+
+#endif // endif TRAVERSO_TYPES_H
+
+//eof
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Traverso-commit] traverso/src/common Utils.cpp Utils.h defines.h,
Remon Sijrier <=