diff --git a/include/FluidSCWrapper.hpp b/include/FluidSCWrapper.hpp index 4bed7f7..0a34049 100644 --- a/include/FluidSCWrapper.hpp +++ b/include/FluidSCWrapper.hpp @@ -340,6 +340,12 @@ class FluidSCWrapper : public impl::FluidSCWrapperBase return BufferT::type(bufnum >= 0 ? new SCBufferAdaptor(bufnum, w) : nullptr); } + auto fromArgs(World *w, ArgType args, InputBufferT::type, int) + { + typename LongT::type bufnum = static_cast(fromArgs(w, args, LongT::type(), -1)); + return InputBufferT::type(bufnum >= 0 ? new SCBufferAdaptor(bufnum, w) : nullptr); + } + typename T::type operator()(World *w, ArgType args) { ParamLiteralConvertor a; diff --git a/include/SCBufferAdaptor.hpp b/include/SCBufferAdaptor.hpp index 23c4bf1..01162d5 100644 --- a/include/SCBufferAdaptor.hpp +++ b/include/SCBufferAdaptor.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -93,8 +94,8 @@ public: } // No locks in (vanilla) SC, so no-ops for these - bool acquire() override { return true; } - void release() override {} + bool acquire() const override { return true; } + void release() const override {} // Validity is based on whether this buffer is within the range the server // knows about @@ -117,7 +118,6 @@ public: return v.col(channel); } - // Return a 2D chunk FluidTensorView samps(size_t offset, size_t nframes, size_t chanoffset) override { @@ -128,6 +128,26 @@ public: return v(fluid::Slice(offset, nframes), fluid::Slice(chanoffset, 1)).col(0); } + const FluidTensorView samps(size_t channel) const override + { + FluidTensorView v{mBuffer->data, 0, + static_cast(mBuffer->frames), + static_cast(mBuffer->channels)}; + + return v.col(channel); + } + + const FluidTensorView samps(size_t offset, size_t nframes, + size_t chanoffset) const override + { + FluidTensorView v{mBuffer->data, 0, + static_cast(mBuffer->frames), + static_cast(mBuffer->channels)}; + + return v(fluid::Slice(offset, nframes), fluid::Slice(chanoffset, 1)).col(0); + } + + size_t numFrames() const override { return valid() ? static_cast(this->mBuffer->frames) : 0u; @@ -140,14 +160,25 @@ public: double sampleRate() const override { return valid() ? mBuffer->samplerate : 0; } - void resize(size_t frames, size_t channels, double sampleRate) override + std::string asString() const override { return std::to_string(bufnum()); } + + const Result resize(size_t frames, size_t channels, double sampleRate) override { SndBuf *thisThing = mBuffer; mOldData = thisThing->data; - mWorld->ft->fBufAlloc(mBuffer, static_cast(channels), static_cast(frames), sampleRate); + int allocResult = mWorld->ft->fBufAlloc(mBuffer, static_cast(channels), static_cast(frames), sampleRate); + + Result r; + + if(allocResult != kSCErr_None) + { + r.set(Result::Status::kError); + r.addMessage("Resize on buffer ", bufnum(), " failed."); + } + return r; } - intptr_t bufnum() { return mBufnum; } + intptr_t bufnum() const { return mBufnum; } void realTime(bool rt) { mRealTime = rt; } protected: