diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 18:37:05 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 18:37:05 +0000 |
commit | 145364a8af6a1fec06556221e66d4b724a62fc9a (patch) | |
tree | 53bd71a544008c518034f208d64c932dc2883f50 /src/sound/AudioCache.h | |
download | rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.tar.gz rosegarden-145364a8af6a1fec06556221e66d4b724a62fc9a.zip |
Added old abandoned KDE3 version of the RoseGarden MIDI tool
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/rosegarden@1097595 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/sound/AudioCache.h')
-rw-r--r-- | src/sound/AudioCache.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/sound/AudioCache.h b/src/sound/AudioCache.h new file mode 100644 index 0000000..6dd55ff --- /dev/null +++ b/src/sound/AudioCache.h @@ -0,0 +1,98 @@ +// -*- c-basic-offset: 4 -*- + +/* + Rosegarden + A sequencer and musical notation editor. + + This program is Copyright 2000-2008 + Guillaume Laurent <[email protected]>, + Chris Cannam <[email protected]>, + Richard Bown <[email protected]> + + The moral right of the authors to claim authorship of this work + has been asserted. + + 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 _AUDIO_CACHE_H_ +#define _AUDIO_CACHE_H_ + +#include <map> + +namespace Rosegarden +{ + +/** + * A simple cache for smallish bits of audio data, indexed by some + * opaque pointer type. (The PlayableAudioFile uses this with an + * AudioFile* index type, for example.) With reference counting. + */ + +class AudioCache +{ +public: + AudioCache() { } + virtual ~AudioCache(); + + /** + * Look some audio data up in the cache and report whether it + * exists. + */ + bool has(void *index); + + /** + * Look some audio data up in the cache and return it if it + * exists, returning the number of channels in channels, the frame + * count in frames, and one pointer per channel to samples in the + * return value. Return 0 if the data is not in cache. Does not + * affect the reference count. Ownership of the returned data + * remains with the cache object. You should not call this unless + * you have already called incrementReference (or addData) to + * register your interest. + */ + float **getData(void *index, size_t &channels, size_t &frames); + + /** + * Add a piece of data to the cache, and increment the reference + * count for that data (to 1). Ownership of the data is passed + * to the cache, which will delete it with delete[] when done. + */ + void addData(void *index, size_t channels, size_t nframes, float **data); + + /** + * Increment the reference count for a given piece of data. + */ + void incrementReference(void *index); + + /** + * Decrement the reference count for a given piece of data, + * and delete the data from the cache if the reference count has + * reached zero. + */ + void decrementReference(void *index); + +protected: + void clear(); + + struct CacheRec { + CacheRec() : data(0), channels(0), nframes(0), refCount(0) { } + CacheRec(float **d, size_t c, size_t n) : + data(d), channels(c), nframes(n), refCount(1) { } + ~CacheRec(); + float **data; + size_t channels; + size_t nframes; + int refCount; + }; + + std::map<void *, CacheRec *> m_cache; +}; + +} + +#endif |