From f94db030b54fc4073b486f193876e60b35971755 Mon Sep 17 00:00:00 2001 From: dave griffiths Date: Mon, 26 Sep 2016 15:19:17 +0100 Subject: [PATCH] windows loading fix and streaming debug --- samplebrain/src/jellyfish/sample.cpp | 8 +- samplebrain/src/jellyfish/stream.cpp | 105 ++++++++------------------- samplebrain/src/jellyfish/stream.h | 69 ++++++++++-------- 3 files changed, 70 insertions(+), 112 deletions(-) diff --git a/samplebrain/src/jellyfish/sample.cpp b/samplebrain/src/jellyfish/sample.cpp index 38a8fcb..238c85f 100644 --- a/samplebrain/src/jellyfish/sample.cpp +++ b/samplebrain/src/jellyfish/sample.cpp @@ -315,8 +315,8 @@ ios &spiralcore::operator||(ios &s, sample &sa) { ofstream *pos=dynamic_cast(&s); if (pos!=NULL) { ofstream &os = *pos; - size_t len = sa.m_length; - os.write((char*)&len,sizeof(size_t)); + u64 len = sa.m_length; + os.write((char*)&len,sizeof(u64)); os.write((char*)sa.m_data,sa.m_length*sizeof(audio_type)); return os; } @@ -325,8 +325,8 @@ ios &spiralcore::operator||(ios &s, sample &sa) { ifstream *pis=dynamic_cast(&s); assert(pis!=NULL); ifstream &is = *pis; - size_t len=0; - is.read((char *)&len,sizeof(size_t)); + u64 len=0; + is.read((char *)&len,sizeof(u64)); float *data = new float[len]; is.read((char*)data,len*sizeof(audio_type)); sa.m_data = data; diff --git a/samplebrain/src/jellyfish/stream.cpp b/samplebrain/src/jellyfish/stream.cpp index 39c8354..50d47ea 100644 --- a/samplebrain/src/jellyfish/stream.cpp +++ b/samplebrain/src/jellyfish/stream.cpp @@ -25,85 +25,38 @@ using namespace std; template<>ios &spiralcore::operator||(ios &s, string &v) { ofstream *pos=dynamic_cast(&s); if (pos!=NULL) { - ofstream &os = *pos; - u64 len = v.length(); - os.write((char *)&len,sizeof(u64)); - os.write((char*)(v.c_str()),v.length()); - return os; - } - else - { - ifstream *pis=dynamic_cast(&s); - assert(pis!=NULL); - ifstream &is = *pis; - u64 len=0; - is.read((char *)&len,sizeof(u64)); - if (len>0) { - char *str = new char[len+1]; - is.read(str,len); - str[len]='\0'; - v = string(str); - delete[] str; - } - else { - //v=string(""); - } - return is; + #ifdef DEBUG_STREAM + cerr<<"streaming out string "<(&s); + assert(pis!=NULL); + ifstream &is = *pis; + u64 len=0; + is.read((char *)&len,sizeof(u64)); + if (len>0) { + char *str = new char[len+1]; + is.read(str,len); + str[len]='\0'; + v = string(str); + delete[] str; + } else { + //v=string(""); + } + + #ifdef DEBUG_STREAM + cerr<<"streamed in string "< &v) { - ofstream *pos=dynamic_cast(&s); - if (pos!=NULL) { - ofstream &os = *pos; - size_t len = v.length(); - os.write((char *)&len,sizeof(size_t)); - return os.write((char*)(&v[0]),v.length()*sizeof(U)); - } - else - { - ifstream *pis=dynamic_cast(&s); - assert(pis); - ifstream &is = *pis; - size_t len=0; - is.read((char *)&len,sizeof(size_t)); - v.reserve(len); - is.read((char*)&v[0],len); - return is; - } - - - }*/ -/* -templateios &operator||(ios &s, vector &v) { - ofstream *pos=dynamic_cast(&s); - if (pos!=NULL) { - ofstream &os = *pos; - size_t len = v.length(); - for (size_t i=0; i(&s); - assert(pis); - ifstream &is = *pis; - size_t len=0; - is.read((char *)&len,sizeof(size_t)); - v.reserve(len); - for (size_t i=0; i #include #include +#include "types.h" #pragma once +//#define DEBUG_STREAM + +#ifdef DEBUG_STREAM +#include +#endif + namespace spiralcore { // hack to do both stream directions in one function // saw this years ago at computer artworks, not seen it since... templatestd::ios &operator||(std::ios &s, T &v) { + +#ifdef DEBUG_STREAM + std::cerr<<"streaming a "<(&s); if (pos!=NULL) { std::ofstream &os = *pos; @@ -47,34 +59,18 @@ templatestd::ios &operator||(std::ios &s, T &v) { template<>std::ios &operator||(std::ios &s, std::string &v); -/* -templateT *stream_array(std::ios &s, T *v, U &len) { - std::ofstream *pos=dynamic_cast(&s); - if (pos!=NULL) { - std::ofstream &os = *pos; - os||len; - os.write((char*)v,sizeof(T)*len); - return v; - } else { - std::ifstream *pis=dynamic_cast(&s); - assert(pis); - std::ifstream &is = *pis; - is||len; - if (v!=NULL) delete[] v; - T* t = new T[len]; - is.read((char *)t,sizeof(T)*len); - return t; - } -} -*/ - templatestd::ios &stream_vector(std::ios &s, std::vector &v) { std::ofstream *pos=dynamic_cast(&s); + +#ifdef DEBUG_STREAM + std::cerr<<"streaming a vector "<std::ios &stream_vector(std::ios &s, std::vector &v) { std::ifstream *pis=dynamic_cast(&s); assert(pis); std::ifstream &is = *pis; - size_t len=0; + u64 len=0; is||len; //v.reserve(len); v.clear(); - for (size_t i=0; istd::ios &stream_vector(std::ios &s, std::vector &v) { // skip a vector when loading templatestd::ios &skip_vector(std::ifstream &is) { - size_t len=0; +#ifdef DEBUG_STREAM + std::cerr<<"skipping a vector"<std::ios &skip_vector(std::ifstream &is) { templatestd::ios &stream_list(std::ios &s, std::list &v) { std::ofstream *pos=dynamic_cast(&s); +#ifdef DEBUG_STREAM + std::cerr<<"streaming a list"<::iterator i=v.begin(); i!=v.end(); ++i) { os||*i; @@ -125,9 +127,9 @@ templatestd::ios &stream_list(std::ios &s, std::list &v) { std::ifstream *pis=dynamic_cast(&s); assert(pis); std::ifstream &is = *pis; - size_t len=0; + u64 len=0; is||len; - for (size_t i=0; istd::ios &stream_list(std::ios &s, std::list &v) { } templatestd::ios &skip_list(std::istream &is) { - size_t len=0; +#ifdef DEBUG_STREAM + std::cerr<<"skipping a list"<