Adding C++ STL to OsciStudio


#1

Is there a particular reason why the stl isn’t a part of the livecoding feature? I was thinking about trying to somehow add it in myself, but since I’m a pretty novice coder, I wasn’t sure if there might be a good reason that you wouldn’t want to do this. If it isn’t a bad idea, how would one go about doing this?


#2

unfortunately STL is very problematic for a few reasons:

  1. it requires malloc/free, but i don’t allow those (no dynamic memory at this point)
  2. STL is typically part of the system distribution of a compiler and gigantic, i’ve stripped clang to be basically only the “c++ language” without any libs
  3. you would get access to a lot of tempting functionality like reading/writing files, which really shouldn’t be done in the audio thread.

i’ve been looking into projects like EASTL/tinystl, but haven’t gotten far and it’s really not high priority for me. is there anything particular you’re missing?


#3

Not really. I just found it difficult to say, have an array of things I’m going to draw, and add and remove them from an array. The sort of thing where defining the size of the array before hand can be hard if you don’t already know how many circles you’re going to draw. The most recent problem I had was drawing a fractal, but having to determine how many points I needed before performing any calculations.


#4

if you have only a small handfull of things, then the phasecutter is your friend.

i’d say the phasecutter is a bit underappreciated, but you can do stuff like this:

 #include <PhaseCut.h>

 SLIDER(brightness_1); 
 SLIDER(brightness_2); 
 SLIDER(brightness_3); 
 
 vec3 shape_1(float t){ ... your code }
 vec3 shape_2(float t){ ... your code }
 vec3 shape_3(float t){ ... your code }
 
 vec3 gen(float t){
   PhaseCut cut = cut_weights(t, brightness_1, brightness_2, brightness_3); 
   vec3 v; 
   if(cut.idx == 0) v = shape_1(cut.t); 
   else if(cut.idx==1) v = shape_2(cut.t); 
   else if(cut.idx==2) v = shape_3(cut.t); 

   return v; 
 }

there is also a pathrecorder, but it’s for fixed length arrays so it doesn’t help yet with your array.

btw: did you find the doxygen docs in the download?


#5

Yeah, I’ve slowly been tinkering with things. I was using PathRecorder to draw a dragon curve. Understanding PhaseCutter, and Remapping Tree are next on the list. I’m currently trying to figure out how to implement some sort of L-system + path recorder combo.


#6

i’ve played with L-systems extensively.
in my experience you want to never store anything, recursion is your friend to generate it point by point on demand.

overal, that’s the strategy i find works best and is very performant. it’s just not a very natural way of thinking.


#7

Thanks for the tips!