amuse/AudioUnit/AudioGroupFilePresenter.hpp

132 lines
4.5 KiB
C++
Raw Normal View History

#ifndef __AMUSE_AUDIOUNIT_AUDIOGROUPFILEPRESENTER_HPP__
#define __AMUSE_AUDIOUNIT_AUDIOGROUPFILEPRESENTER_HPP__
#import <Foundation/Foundation.h>
2016-06-03 02:53:52 +00:00
#import <AppKit/AppKit.h>
#include <map>
#include <string>
2016-06-04 02:34:35 +00:00
#include "optional.hpp"
#include <amuse/amuse.hpp>
#include <athena/FileReader.hpp>
@class AudioGroupFilePresenter;
2016-06-04 02:34:35 +00:00
@class AudioGroupDataToken;
@class AudioGroupCollectionToken;
struct AudioGroupDataCollection
{
2016-06-04 02:34:35 +00:00
std::string m_name;
2016-06-03 02:53:52 +00:00
NSURL* m_proj;
NSURL* m_pool;
NSURL* m_sdir;
NSURL* m_samp;
2016-06-04 02:34:35 +00:00
NSURL* m_meta;
AudioGroupDataToken* m_token;
std::vector<uint8_t> m_projData;
std::vector<uint8_t> m_poolData;
std::vector<uint8_t> m_sdirData;
std::vector<uint8_t> m_sampData;
struct MetaData
{
amuse::DataFormat fmt;
uint32_t absOffs;
uint32_t active;
MetaData(amuse::DataFormat fmtIn, uint32_t absOffsIn, uint32_t activeIn)
: fmt(fmtIn), absOffs(absOffsIn), active(activeIn) {}
MetaData(athena::io::FileReader& r)
: fmt(amuse::DataFormat(r.readUint32Big())), absOffs(r.readUint32Big()), active(r.readUint32Big()) {}
};
std::experimental::optional<MetaData> m_metaData;
2016-06-03 02:53:52 +00:00
2016-06-04 02:34:35 +00:00
std::experimental::optional<amuse::AudioGroupData> m_loadedData;
std::experimental::optional<amuse::AudioGroupProject> m_loadedProj;
void moveURL(NSURL* oldUrl, NSURL* newUrl);
2016-06-03 02:53:52 +00:00
bool loadProj(AudioGroupFilePresenter* presenter);
bool loadPool(AudioGroupFilePresenter* presenter);
bool loadSdir(AudioGroupFilePresenter* presenter);
bool loadSamp(AudioGroupFilePresenter* presenter);
2016-06-04 02:34:35 +00:00
bool loadMeta(AudioGroupFilePresenter* presenter);
2016-06-04 02:34:35 +00:00
AudioGroupDataCollection(const std::string& name, NSURL* proj, NSURL* pool, NSURL* sdir, NSURL* samp, NSURL* meta);
bool isDataComplete() const {return m_projData.size() && m_poolData.size() && m_sdirData.size() && m_sampData.size() && m_metaData;}
bool _attemptLoad(AudioGroupFilePresenter* presenter);
};
template <class T>
class IteratorTracker
{
typename std::map<std::string, T>::const_iterator m_audioGroupOutlineBegin;
typename std::map<std::string, T>::const_iterator m_audioGroupOutlineEnd;
typename std::map<std::string, T>::const_iterator m_audioGroupOutlineIt;
size_t m_audioGroupOutlineIdx = 0;
public:
IteratorTracker(typename std::map<std::string, T>::const_iterator begin,
typename std::map<std::string, T>::const_iterator end)
: m_audioGroupOutlineBegin(begin), m_audioGroupOutlineEnd(end), m_audioGroupOutlineIt(begin) {}
typename std::map<std::string, T>::const_iterator seekToIndex(size_t idx)
{
if (idx == m_audioGroupOutlineIdx)
return m_audioGroupOutlineIt;
if (idx < m_audioGroupOutlineIdx)
{
for (; idx < m_audioGroupOutlineIdx && m_audioGroupOutlineIt != m_audioGroupOutlineBegin ;
--m_audioGroupOutlineIdx, --m_audioGroupOutlineIt) {}
return m_audioGroupOutlineIt;
}
for (; idx > m_audioGroupOutlineIdx && m_audioGroupOutlineIt != m_audioGroupOutlineEnd ;
++m_audioGroupOutlineIdx, ++m_audioGroupOutlineIt) {}
return m_audioGroupOutlineIt;
}
};
struct AudioGroupCollection
{
NSURL* m_url;
AudioGroupCollectionToken* m_token;
std::map<std::string, AudioGroupDataCollection> m_groups;
std::experimental::optional<IteratorTracker<AudioGroupDataCollection>> m_iteratorTracker;
AudioGroupCollection(NSURL* url);
void addCollection(std::vector<std::pair<std::string, amuse::IntrusiveAudioGroupData>>&& collection);
void update(AudioGroupFilePresenter* presenter);
};
2016-06-04 02:34:35 +00:00
@interface AudioGroupDataToken : NSObject
{
@public
AudioGroupDataCollection* m_collection;
}
- (id)initWithDataCollection:(AudioGroupDataCollection*)collection;
@end
@interface AudioGroupCollectionToken : NSObject
{
@public
AudioGroupCollection* m_collection;
}
- (id)initWithCollection:(AudioGroupCollection*)collection;
@end
@interface AudioGroupFilePresenter : NSObject <NSFilePresenter, NSOutlineViewDataSource, NSOutlineViewDelegate>
{
NSURL* m_groupURL;
NSOperationQueue* m_dataQueue;
2016-06-04 02:34:35 +00:00
std::map<std::string, AudioGroupCollection> m_audioGroupCollections;
NSOutlineView* lastOutlineView;
2016-06-03 02:53:52 +00:00
2016-06-04 02:34:35 +00:00
std::experimental::optional<IteratorTracker<AudioGroupCollection>> m_iteratorTracker;
}
2016-06-04 02:34:35 +00:00
- (BOOL)addCollectionName:(std::string&&)name items:(std::vector<std::pair<std::string, amuse::IntrusiveAudioGroupData>>&&)collection;
2016-06-03 02:53:52 +00:00
- (void)update;
2016-06-04 02:34:35 +00:00
- (void)resetIterators;
@end
#endif // __AMUSE_AUDIOUNIT_AUDIOGROUPFILEPRESENTER_HPP__