threadutilities.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *
00003  *   ::::_audioeditor_::::
00004  *   a simple multitrack audio editor
00005  *
00006  *   threadutilities
00007  *   header file
00008  *
00009  *   begin                : Jan 2006
00010  *   copyright            : (C) 2006 by Georg Holzmann
00011  *   email                : grh@mur.at
00012  *
00013  *   This program is free software; you can redistribute it and/or modify
00014  *   it under the terms of the GNU General Public License as published by
00015  *   the Free Software Foundation; either version 2 of the License, or
00016  *   (at your option) any later version.
00017  *
00018  ***************************************************************************/
00019 
00020 #ifndef THREADUTILITIES_H__
00021 #define THREADUTILITIES_H__
00022 
00032 #include <QMutex>
00033 #include "globaldefines.h"
00034 #include "portaudio.h"
00035 
00041 class MutexPos
00042 {
00043   public:
00044     MutexPos() : m_pos(0) {}
00045     virtual ~MutexPos() {}
00046     inline Position get() const { QMutexLocker locker(&m_mutex); return m_pos;  }
00047     inline void set(Position pos) { QMutexLocker locker(&m_mutex); m_pos = pos; }
00048     inline void add(Position nr) { QMutexLocker locker(&m_mutex); m_pos += nr; }
00049     
00050   protected:
00051     mutable QMutex m_mutex;
00052     Position m_pos;
00053     
00054   private:
00056     MutexPos(const MutexPos &src) { m_pos = src.m_pos; }
00057     const MutexPos operator = (const MutexPos) { return *this; }
00058 };
00059 
00060 #include <QList>
00061 #include <QReadWriteLock>
00062 
00071 class FuncList
00072 {
00073   public:
00074     FuncList() : m_callback(0) {}
00075     virtual ~FuncList() {}
00076     
00078     inline void append(PortAudioCallback *callback)
00079     {
00080       m_lock.lockForWrite();
00081       m_list.append(callback);
00082       m_lock.unlock();
00083     }
00084     
00086     inline void removeAll(PortAudioCallback *callback)
00087     {
00088       m_lock.lockForWrite();
00089       m_list.removeAll(callback);
00090       m_lock.unlock();
00091     }
00092     
00094     inline void callAll(void *inputBuffer, void *outputBuffer,
00095                         unsigned long framesPerBuffer,
00096                         PaTimestamp outTime, void *userData )
00097     {
00098       m_lock.lockForRead();
00099       foreach (m_callback, m_list)
00100         m_callback(inputBuffer, outputBuffer, framesPerBuffer, outTime, userData);
00101       m_lock.unlock();
00102     }
00103     
00104   protected:
00105     QReadWriteLock m_lock;
00106     QList<PortAudioCallback *> m_list;
00107     PortAudioCallback *m_callback;
00108     
00109   private:
00111     FuncList(const FuncList &src) { m_list = src.m_list; }
00112     const FuncList operator = (const FuncList) { return *this; }
00113 };
00114 
00115 #endif // THREADUTILITIES_H__

Generated on Fri Jul 6 12:38:40 2007 for audioeditor.kdevelop by  doxygen 1.5.2