How to Write BBCut FX

First, here’s my file:

CutMask : CutSynth { 
 var bits,sr,bitadd,srmult; 
 var synthid;
 
 //makes SynthDef for filter FX Synth 
 *initClass { 
 
   StartUp.add({
  
  2.do({arg i;

  SynthDef.writeOnce("cutmaskchan"++((i+1).asSymbol),{ arg inbus=0, outbus=0, bits; 
  var input, fx;
  
  input= In.ar(inbus,i+1);
  
  fx = MantissaMask.ar(input, bits);
  
  ReplaceOut.ar(outbus,fx);
  
  }); 
  });
  
  });
  
 } 
 
 *new{arg bits=16,sr,bitadd=1,srmult=1;
  
 ^super.new.bits_(bits).bitadd_(bitadd).sr_(sr ?? {Server.default.sampleRate/2}).srmult_(srmult);
 }
 
 setup { 
 //tail of cutgroup
 synthid= cutgroup.server.nextNodeID;
  
 cutgroup.server.sendMsg(s_new, cutmaskchan++(cutgroup.numChannels.asSymbol), synthid, 1,cutgroup.fxgroup.nodeID,inbus,cutgroup.index,outbus,cutgroup.index, bits, bits);
   
 } 


//can't assume, individual free required for cut fx
//synth should be freed automatically by group free
 free {
  cutgroup.server.sendMsg(n_free,synthid); 
 }

 renderBlock {arg block,clock;
  var samprate,bitstart,bitarray,srarray, s;
  
  s= cutgroup.server;

  bitstart= bits.value(block);
  samprate= sr.value(block);
  
  srarray= Array.geom(block.cuts.size,samprate,srmult.value(block));
  bitarray= Array.series(block.cuts.size,bitstart,bitadd.value(block));

  bitarray= 0.5**((bitarray).max(2)-1);

  block.cuts.do({arg cut,i;
  
  block.msgs[i].add([n_set, synthid,bits,bits]);
  
  });
  
  //don't need to return block, updated by reference
 }
 

}

What I did there: I took CutBit1.sc and did a saveAs CutMask.sc. Then I changed the name of the class to CutMask.

In initClass

I changed the synthdef name to cutmaskchan
I changed the arguments to the SynthDef
I put in my own code for the fx = line. That’s where the magic happens!

In new

I changed cutgroup.server.sendMsg to so it uses my synthdef name and my synthdef arguments

In renderBlock

I changed block.msgs[i].add( to have my synthdef arguments
since mine doesn’t change, I could skip sending anything, afaik

Published by

Charles Céleste Hutchins

Supercolliding since 2003

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.