Optionally copy data from first stream when expanding to allow messages before expansion to work
This commit is contained in:
@@ -6,7 +6,10 @@
|
||||
|
||||
class FrameLib_MaxClass_FromMax : public FrameLib_MaxClass_Expand<FrameLib_FromHost>
|
||||
{
|
||||
struct FromHostProxy : public FrameLib_FromHost::Proxy, public FrameLib_MaxProxy {};
|
||||
struct FromHostProxy : public FrameLib_FromHost::Proxy, public FrameLib_MaxProxy
|
||||
{
|
||||
FromHostProxy() : FrameLib_FromHost::Proxy(true) {}
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ void FrameLib_FromHost::Proxy::sendFromHost(unsigned long index, const double *v
|
||||
|
||||
void FrameLib_FromHost::Proxy::sendFromHost(unsigned long index, unsigned long stream, const double *values, unsigned long N)
|
||||
{
|
||||
// Copy vector and swap(deconstructing the old vector in this thread)
|
||||
// Copy vector and swap (deconstructing the old vector in this thread)
|
||||
|
||||
OwnedFrame inputSwap(new std::vector<double>(values, values + N));
|
||||
getObject(index, stream)->swapVectorFrame(inputSwap);
|
||||
@@ -80,6 +80,35 @@ void FrameLib_FromHost::Proxy::sendFromHost(unsigned long index, unsigned long s
|
||||
sendFromHost(index, stream, &serial);
|
||||
}
|
||||
|
||||
// Copy data from the first stream
|
||||
|
||||
void FrameLib_FromHost::Proxy::copyData(void *streamOwner, unsigned long stream)
|
||||
{
|
||||
if (stream && mCopyStreams)
|
||||
{
|
||||
FrameLib_FromHost *first = getObject(streamOwner, 0);
|
||||
FrameLib_FromHost *current = getObject(streamOwner, stream);
|
||||
|
||||
if (first->mMode == kValues && current->mMode == kValues)
|
||||
{
|
||||
first->mLock.acquire();
|
||||
OwnedFrame frame(new std::vector<double>(*first->mVectorFrame.get()));
|
||||
first->mLock.release();
|
||||
current->swapVectorFrame(frame);
|
||||
}
|
||||
else if (first->mMode == kParams && current->mMode == kParams)
|
||||
{
|
||||
FrameLib_Parameters::AutoSerial serial;
|
||||
SerialList freeList;
|
||||
|
||||
first->mLock.acquire();
|
||||
SerialList::Item *addSerial = new SerialList::Item(first->mSerialFrame);
|
||||
first->mLock.release();
|
||||
current->updateSerialFrame(freeList, addSerial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FrameLib_FromHost Class
|
||||
|
||||
// Constructor
|
||||
@@ -110,14 +139,17 @@ FrameLib_FromHost::~FrameLib_FromHost()
|
||||
|
||||
void FrameLib_FromHost::setStream(void *streamOwner, unsigned long stream)
|
||||
{
|
||||
if (mProxy)
|
||||
{
|
||||
mProxy->unregisterObject(this, mStreamOwner, mStream);
|
||||
mProxy->registerObject(this, streamOwner, stream);
|
||||
}
|
||||
|
||||
void *prevOwner = mStreamOwner;
|
||||
unsigned long prevStream = mStream;
|
||||
mStreamOwner = streamOwner;
|
||||
mStream = stream;
|
||||
|
||||
if (mProxy)
|
||||
{
|
||||
mProxy->unregisterObject(this, prevOwner, prevStream);
|
||||
mProxy->registerObject(this, streamOwner, stream);
|
||||
mProxy->copyData(streamOwner, stream);
|
||||
}
|
||||
}
|
||||
|
||||
// Info
|
||||
|
||||
@@ -22,7 +22,12 @@ class FrameLib_FromHost final : public FrameLib_Processor
|
||||
{
|
||||
Item() : mNext(nullptr) {}
|
||||
Item(const FrameLib_Parameters::Serial& serial) : mSerial(serial), mNext(nullptr) {}
|
||||
|
||||
Item(const SerialList& list) : mNext(nullptr)
|
||||
{
|
||||
for (Item *item = list.mTop; item; item = list.mTail == item ? nullptr : item->mNext)
|
||||
mSerial.write(&item->mSerial);
|
||||
}
|
||||
|
||||
FrameLib_Parameters::AutoSerial mSerial;
|
||||
Item *mNext;
|
||||
};
|
||||
@@ -101,6 +106,8 @@ public:
|
||||
|
||||
struct Proxy : public FrameLib_HostProxy<FrameLib_FromHost>
|
||||
{
|
||||
Proxy(bool copyStreams) : mCopyStreams(copyStreams) {}
|
||||
|
||||
// Send a vector frame
|
||||
|
||||
void sendFromHost(unsigned long index, const double *values, unsigned long N);
|
||||
@@ -120,6 +127,12 @@ public:
|
||||
|
||||
void sendFromHost(unsigned long index, const char *tag, const double *values, unsigned long N);
|
||||
void sendFromHost(unsigned long index, unsigned long stream, const char *tag, const double *values, unsigned long N);
|
||||
|
||||
// Copy data from the first stream to another stream
|
||||
|
||||
void copyData(void *streamOwner, unsigned long stream);
|
||||
|
||||
bool mCopyStreams;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -15,6 +15,26 @@ class FrameLib_HostProxy : public virtual FrameLib_Proxy
|
||||
std::vector<T *> mObjects;
|
||||
};
|
||||
|
||||
const std::vector<T *> *getObjectList(void *streamOwner)
|
||||
{
|
||||
for (auto it = mRegistered.begin(); it != mRegistered.end(); it++)
|
||||
{
|
||||
// Find the owner first and if it exists insert into the stream list
|
||||
|
||||
if (it->mStreamOwner == streamOwner)
|
||||
return &it->mObjects;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
T *getObject(void *streamOwner, unsigned long stream)
|
||||
{
|
||||
const std::vector<T *> *objects = getObjectList(streamOwner);
|
||||
|
||||
return objects ? (*objects)[stream] : nullptr;
|
||||
}
|
||||
|
||||
const std::vector<T *>& getObjectList(unsigned long index) { return mRegistered[index].mObjects; }
|
||||
T *getObject(unsigned long index, unsigned long stream) { return mRegistered[index].mObjects[stream]; }
|
||||
|
||||
@@ -29,7 +49,7 @@ class FrameLib_HostProxy : public virtual FrameLib_Proxy
|
||||
if (it->mObjects.size() <= stream)
|
||||
it->mObjects.resize(stream + 1);
|
||||
else
|
||||
assert ((it->mObjects[stream] == nullptr) && "stream is already registered");
|
||||
assert((it->mObjects[stream] == nullptr) && "stream is already registered");
|
||||
|
||||
it->mObjects[stream] = object;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user