# HG changeset patch # User Chris Cannam # Date 1147106687 0 # Node ID 61a2ac1241b37885d39e4716ff761c0ee92e45d0 # Parent 0c19e50bad7c35070e2a1939c19dd16505a7aab8 * Make a single base Thread class for RT and non-RT threads * Pull ResizeableBitmap out from the MatrixFile's ColumnBitmap * Reorder SpectrogramLayer::paint somewhat so as to improve cache hit ratio in the FFT file cache diff -r 0c19e50bad7c -r 61a2ac1241b3 base/NonRTThread.cpp --- a/base/NonRTThread.cpp Mon May 08 13:51:16 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ - -/* - Sonic Visualiser - An audio file viewer and annotation editor. - Centre for Digital Music, Queen Mary, University of London. - This file copyright 2006 Chris Cannam. - - This program 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. See the file - COPYING included with this distribution for more information. -*/ - -#include "NonRTThread.h" - -#ifndef _WIN32 -#include -#endif - -NonRTThread::NonRTThread(QObject *parent) : - QThread(parent) -{ - setStackSize(512 * 1024); -} - -void -NonRTThread::start() -{ - QThread::start(); - -#ifndef _WIN32 - struct sched_param param; - ::memset(¶m, 0, sizeof(param)); - - if (::pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m)) { - ::perror("pthread_setschedparam to SCHED_OTHER failed"); - } -#endif -} - diff -r 0c19e50bad7c -r 61a2ac1241b3 base/NonRTThread.h --- a/base/NonRTThread.h Mon May 08 13:51:16 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ - -/* - Sonic Visualiser - An audio file viewer and annotation editor. - Centre for Digital Music, Queen Mary, University of London. - This file copyright 2006 Chris Cannam. - - This program 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. See the file - COPYING included with this distribution for more information. -*/ - -#ifndef _NON_RT_THREAD_H_ -#define _NON_RT_THREAD_H_ - -#include - -class NonRTThread : public QThread -{ -Q_OBJECT - -public: - NonRTThread(QObject *parent = 0); - -public slots: - void start(); -}; - -#endif diff -r 0c19e50bad7c -r 61a2ac1241b3 base/ResizeableBitmap.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/ResizeableBitmap.h Mon May 08 16:44:47 2006 +0000 @@ -0,0 +1,69 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2006 Chris Cannam. + + This program 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. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _RESIZEABLE_BITMAP_H_ +#define _RESIZEABLE_BITMAP_H_ + +#include +#include + +class ResizeableBitmap { + +public: + ResizeableBitmap() : m_bits(0) { + } + ResizeableBitmap(size_t size) : m_bits(new std::vector) { + m_bits->assign(size / 8 + 1, 0); + } + ResizeableBitmap(const ResizeableBitmap &b) { + m_bits = new std::vector(*b.m_bits); + } + ResizeableBitmap &operator=(const ResizeableBitmap &b) { + if (&b != this) return *this; + delete m_bits; + m_bits = new std::vector(*b.m_bits); + return *this; + } + ~ResizeableBitmap() { + delete m_bits; + } + + void resize(size_t bits) { // losing all data + if (!m_bits || bits < m_bits->size()) { + delete m_bits; + m_bits = new std::vector; + } + m_bits->assign(bits / 8, 0); + } + + bool get(size_t column) const { + return ((*m_bits)[column / 8]) & (1u << (column % 8)); + } + + void set(size_t column, bool state) { + if (state) { + ((*m_bits)[column / 8]) |= (uint8_t(1) << (column % 8)); + } else { + ((*m_bits)[column / 8]) &= ~(uint8_t(1) << (column % 8)); + } + } + +private: + std::vector *m_bits; +}; + + +#endif + diff -r 0c19e50bad7c -r 61a2ac1241b3 base/Thread.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/Thread.cpp Mon May 08 16:44:47 2006 +0000 @@ -0,0 +1,55 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2006 Chris Cannam. + + This program 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. See the file + COPYING included with this distribution for more information. +*/ + +#include "Thread.h" + +#ifndef _WIN32 +#include +#endif + +Thread::Thread(Type type, QObject *parent) : + QThread(parent), + m_type(type) +{ + setStackSize(512 * 1024); +} + +void +Thread::start() +{ + QThread::start(); + +#ifndef _WIN32 + struct sched_param param; + ::memset(¶m, 0, sizeof(param)); + + if (m_type == RTThread) { + + param.sched_priority = 5; + + if (::pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m)) { + ::perror("INFO: pthread_setschedparam to SCHED_FIFO failed"); + } + + } else { + + if (::pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m)) { + ::perror("WARNING: pthread_setschedparam to SCHED_OTHER failed"); + } + } + +#endif +} + diff -r 0c19e50bad7c -r 61a2ac1241b3 base/Thread.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/Thread.h Mon May 08 16:44:47 2006 +0000 @@ -0,0 +1,37 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2006 Chris Cannam. + + This program 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. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _THREAD_H_ +#define _THREAD_H_ + +#include + +class Thread : public QThread +{ +Q_OBJECT + +public: + enum Type { RTThread, NonRTThread }; + + Thread(Type type = NonRTThread, QObject *parent = 0); + +public slots: + void start(); + +private: + Type m_type; +}; + +#endif diff -r 0c19e50bad7c -r 61a2ac1241b3 base/View.cpp --- a/base/View.cpp Mon May 08 13:51:16 2006 +0000 +++ b/base/View.cpp Mon May 08 16:44:47 2006 +0000 @@ -31,7 +31,7 @@ #include #include -#define DEBUG_VIEW_WIDGET_PAINT 1 +//#define DEBUG_VIEW_WIDGET_PAINT 1 using std::cerr; using std::endl; diff -r 0c19e50bad7c -r 61a2ac1241b3 plugin/DSSIPluginInstance.h --- a/plugin/DSSIPluginInstance.h Mon May 08 13:51:16 2006 +0000 +++ b/plugin/DSSIPluginInstance.h Mon May 08 16:44:47 2006 +0000 @@ -32,7 +32,7 @@ #include "api/dssi.h" #include "base/RingBuffer.h" -#include "base/NonRTThread.h" +#include "base/Thread.h" #include "RealTimePluginInstance.h" #include "base/Scavenger.h" @@ -198,7 +198,7 @@ static Scavenger > m_bufferScavenger; - class NonRTPluginThread : public NonRTThread + class NonRTPluginThread : public Thread { public: NonRTPluginThread(LADSPA_Handle handle, diff -r 0c19e50bad7c -r 61a2ac1241b3 transform/Transform.h --- a/transform/Transform.h Mon May 08 13:51:16 2006 +0000 +++ b/transform/Transform.h Mon May 08 16:44:47 2006 +0000 @@ -16,7 +16,7 @@ #ifndef _TRANSFORM_H_ #define _TRANSFORM_H_ -#include "NonRTThread.h" +#include "Thread.h" #include "base/Model.h" @@ -35,7 +35,7 @@ * the background thread has populated it. */ -class Transform : public NonRTThread +class Transform : public Thread { public: virtual ~Transform();