DataStream.hpp
1 #pragma once
2 #include <QDataStream>
3 #include <QIODevice>
4 
5 #include <pluginterfaces/base/ibstream.h>
6 
7 namespace vst3
8 {
9 struct Vst3DataStream : public Steinberg::IBStream
10 {
11 public:
12  QDataStream& stream;
13  explicit Vst3DataStream(QDataStream& s)
14  : stream{s}
15  {
16  s.setByteOrder(QDataStream::LittleEndian);
17  }
18  Steinberg::tresult queryInterface(const Steinberg::TUID _iid, void** obj) override
19  {
20  return Steinberg::kResultFalse;
21  }
22  Steinberg::uint32 addRef() override { return 1; }
23  Steinberg::uint32 release() override { return 1; }
24 
25  Steinberg::tresult
26  read(void* buffer, Steinberg::int32 numBytes, Steinberg::int32* numBytesRead) override
27  {
28  int count = stream.readRawData((char*)buffer, numBytes);
29  if(numBytesRead)
30  *numBytesRead = count;
31  return Steinberg::kResultTrue;
32  }
33 
34  Steinberg::tresult write(
35  void* buffer, Steinberg::int32 numBytes,
36  Steinberg::int32* numBytesWritten) override
37  {
38  int count = stream.writeRawData((char*)buffer, numBytes);
39  if(numBytesWritten)
40  *numBytesWritten = count;
41 
42  return Steinberg::kResultTrue;
43  }
44  Steinberg::tresult
45  seek(Steinberg::int64 pos, Steinberg::int32 mode, Steinberg::int64* result) override
46  {
47  bool ok = stream.device()->seek(pos);
48  if(result)
49  *result = stream.device()->pos();
50 
51  return ok ? Steinberg::kResultTrue : Steinberg::kResultFalse;
52  }
53  Steinberg::tresult tell(Steinberg::int64* pos) override
54  {
55  if(pos)
56  *pos = stream.device()->pos();
57 
58  return Steinberg::kResultTrue;
59  }
60 };
61 }
Definition: DataStream.hpp:10