VGSamp a flexible sampler for the VGG gamelan sample database.

superclass VGTuning has gamelan tuning information;

partials-based resonator synthesis is done in VGReson. 

adc, jrh, rschuetz.


Server.default = s = Server.internal; 

s.boot;

(

VGTuning.init(s); // happens on initClass too


VGSamp.dir_(Platform.userAppSupportDir ++ "/vgg/synthData/samples gamKUG/");

VGSamp.prepPaths;


VGSamp.readBufs; // this takes about 15 secs and lots of RAM.

// both pelog and slendro are always loaded. 

)

VGSamp.checkLoaded; // check if buffers seem ok


/////// setup is complete now. ////////////////


/////// tests: ////////////////


VGSamp.playTest(\slendro);

VGSamp.playTest(\pelog);

VGSamp.playTest(\neutral);

VGSamp.playTest; // all three


TdefAllGui.new;

Tdef(\VGSampTest).pause;

Tdef(\VGSampTest).resume;


// VGSamp has a Gui, and the individual sonators can be played from the buttons. 

// tuning parameters from the GUI is not hooked up yet. 

VGSamp.makeWin(\slendro);

VGSamp.makeWin(\pelog);



// sample and file info are sorted apart in 3 dictionaries;

// maybe neutral could have a better name.

VGSamp.instDicts.keys; // these three

VGSamp.instDicts.slendro; // slendro samples are here, 

VGSamp.instDicts.pelog; // pelog samples here,

VGSamp.instDicts.neutral; // all others go here.


// play some notes

VGSamp.eventFor((instKey: \PekingA, \noteKey: \61, amp: 0.2)).play;

VGSamp.eventFor((instKey: \PekingA, \noteKey: \61, amp: 0.2, laras: \pelog)).play;

VGSamp.eventFor((instKey: \PekingA, \noteKey: \63, amp: 0.2)).play;

VGSamp.eventFor((instKey: \PekingA, \noteKey: \63, amp: 0.2, laras: \pelog)).play;


VGSamp.eventFor((instKey: \Kendhang, \noteKey: \g_ket)).put(\amp, 5).play;

VGSamp.eventFor((instKey: \Kendhang, \noteKey: \c_thung, amp: 0.2)).play;

VGSamp.eventFor((instKey: \Kendhang, \noteKey: \c_tapRight, amp: 0.2)).play; // error

VGSamp.eventFor((instKey: \Kendhang, \noteKey: \c_tapLeft, amp: 0.2)).play; // error

VGSamp.eventFor((instKey: \Kendhang, \noteKey: \c_hen, amp: 0.2)).play; // error

VGSamp.eventFor((instKey: \Kendhang, \noteKey: \c_dhen, amp: 0.2)).play;

VGSamp.eventFor((instKey: \Kendhang, \noteKey: \c_ket, amp: 0.2)).play;


// slendro is loaded at the same time.

VGSamp.eventFor((instKey: \PekingA, noteKey: \61, amp: 1, laras: \slendro)).play;

VGSamp.eventFor((instKey: \PekingA, noteKey: \61, amp: 1, laras: \pelog)).play; 

VGSamp.eventFor((instKey: \PekingA, noteKey: \61, amp: 1)).play;


VGSamp.bufenv[\gamKUG_Sl_SaronA_46].duration;


// compare samples between pelog and slendro

VGSamp.keyFor(\DemungA, \43, \pelog); // returns buffername for an istr and note

VGSamp.eventFor((instKey: \DemungA, noteKey: \43, laras: \pelog)).putAll((amp: 2, dur: 10)).play;

VGSamp.keyFor(\DemungA, \43, \slendro); // returns slendro buffername for an instr and note

VGSamp.eventFor((instKey: \DemungA, noteKey: \43, laras: \slendro)).putAll((amp: 1, dur: 10)).play;



// Volume Balancing - SaronA is already balanced:

VGSamp.laras; 

VGSamp.keyFor(instKey: \SaronA, noteKey: \51, laras: \pelog).postcs;

VGSamp.eventFor((instKey: \SaronA, noteKey: \51, amp: 0.2, laras: \pelog)).putAll((dur: 10)).postcs.play;


VGSamp.ampComps['gamKUG_Pl_SaronA_56']

VGSamp.getAmpComp('gamKUG_Pl_SaronA_56');


VGSamp.keyFor(instKey: \SaronA, noteKey: \51, laras: \slendro).postcs;

VGSamp.eventFor((instKey: \SaronA, noteKey: \51, amp: 0.123, laras: \slendro)).putAll((dur: 10)).postcs.play;

VGSamp.getAmpComp('gamKUG_Sl_SaronA_56'); // not balanced yet


// add more balancing data for other instruments here :

Document.open(VGSamp.balancePath);

// maybe use utilites for tuning from here. 

"BalancingVGG_SaronA".openHelpFile;



// Using VGSamp in Patterns:

// in patterns, you pass in an instKey and a noteKey; 

// this creates an event with  the following keys:

// 'instrument' (a synthdefname: vgsamp1), 

// 'bufnum' : the buffer number that vgsamp1 needs for that sample,

// 'out', 'pan': looked up from global instrument settings, 

// unless one passes in a vlue for them

// 'amp': a passed-in value for amp (or a default) is multiplied with

// volumeBalancing and global instrument volume.

VGSamp.keyFor(instKey: \GongAgeng, noteKey: \13, laras: \neutral);

VGSamp.eventFor((instKey: \Kenong, noteKey: \51, laras: \pelog)).play; 

VGSamp.eventFor((instKey: \Kenong, noteKey: \51, laras: \slendro)).play; 

VGSamp.eventFor((instKey: \Kenong, noteKey: \46, laras: \pelog)).play; 

VGSamp.eventFor((instKey: \Kenong, noteKey: \46, laras: \slendro)).play; 


// this event can be played very simply:

VGSamp.eventFor((instKey: \Kenong, noteKey: \51, laras: \pelog)).play;

VGSamp.eventFor((instKey: \Kenong, noteKey: \51, laras: \slendro)).play;


// a pattern that plays all PekingA notes

(

Pdef(\pekingA).clear; 

Pdef(\pekingA, 

Pbind(

\laras, \slendro,

\instKey, \PekingA,

\amp, 1,

\noteKey, Pseq([\56, \61, \62, \63, \65, \66, \71, \rest], inf), 

// *** look up VGSamp info, and post the full event: ***/

\samp, Pfunc({ |ev| ev.putAll(VGSamp.eventFor(ev)); \vgsamp }),

\dur, 0.5

)).play;

)


// all the drum-stroke names you can use: 

VGSamp.instDicts.neutral[\Kendhang].keys.asArray.postcs;


// a stupid pattern that plays all available drum strokes, each one repeated 2-4 times

(

Pdef(\Kendhangan, 

Pbind(

\instKey, \Kendhang, 

\noteKey, Pstutter(Prand([2,3,4], inf), 

Pseq(VGSamp.instDicts.neutral[\Kendhang].keys.asArray, inf)),

\amp, 1,

\dur, Prand( [1/4, 1/8, 1/8], inf),

\samp, Pfunc({ |ev| ev.putAll(VGSamp.eventFor(ev)); \vgsamp })

)

).play;

)


( // play a pattern with all gendhing samples:

Pdef(\Kendhangan, 

Pbind(

\instKey, \Kendhang, // 

\noteKey, Pseq([ 'g_tak', 'g_ket', 'g_thong', 'g_thung', 'g_bem'], inf), \amp, 0.2, 

\pan, 0.5, // pan to the right

\dur, Prand( [1/4, 1/8, 1/8], inf),

// this line will be simpler eventually.

\samp, Pfunc({ |ev| ev.putAll(VGSamp.eventFor(ev)); \vgsamp })

)

).play;

)


// Panning / output modes: 


(

Pdef(\pekingA,

Pbind(

\laras, \pelog,

\instKey, \PekingA,

\amp, 1,

\noteKey, Pseq([\61, \62, \63, \64, \65, \66, \67, \rest], inf), 

\samp, Pfunc({ |ev| ev.putAll(VGSamp.eventFor(ev)); \vgsamp }),

// \pan, 1, // uncomment here to override instrument-based panning

\dur, 0.5

)).play;

)


// panning is looked up in the instrument globals if not given.

VGTuning.setGloBus(\PekingA, \pan, 1); // all right

VGTuning.setGloBus(\PekingA, \pan, 0.0); // center

VGTuning.setGloBus(\PekingA, \pan, -1); // all left


s.scope(8);

// multichannel out: \out is looked up in instrument globals if not given in the pattern.

VGTuning.setGloBus(\PekingA, \out, 4, \pan, -1); 

VGTuning.setGloBus(\PekingA, \out, 2, \pan, -1);

VGTuning.setGloBus(\PekingA, \out, 1, \pan, -1);



// amp: ampComp value, instument value and stream value are multiplied.

VGTuning.setGloBus(\PekingA, \amp, 0); // instrument mute

VGTuning.setGloBus(\PekingA, \amp, 1); // instrument back on

VGTuning.globals[\PekingA]; // all global data for PekingA



(

Pdef(\outTest,

Pbind(

\laras, \slendro,

\instKey, Pseq([ \PekingA, \SaronA, \DemungA, \BonangBar, \BonangPan, \PekingA], inf),

\amp, 1,

\noteKey, Pseq([\61, \51, \41, \41, \51, \rest], inf), 

\samp, Pfunc({ |ev| ev.putAll(VGSamp.eventFor(ev)); \vgsamp }),

\dur, 0.5

)).play;

)

VGSamp.makeWin


( // switch to stereo, with individual panning

(

PekingA: -0.8, 

SaronA: -0.4, 

DemungA: 0.0, 

BonangBar: 0.4,

BonangPan: 0.8

).keysValuesDo { |iname, val| 

VGTuning.setGloBus(iname, \pan, val)

.setGloBus(iname, \out, 0); 

};

)


s.scope(5);

( // switch to multichannel, no panning - multiple mono

(

PekingA: 0, 

SaronA:  1, 

DemungA: 2, 

BonangBar: 3,

BonangPan: 4

).keysValuesDo { |iname, val| 

VGTuning.setGloBus(iname, \out, val)

.setGloBus(iname, \pan, -1);  // = left

};

)




// retuning an instrument:

// retuning by hand, using \rate argument:

VGSamp.eventFor((instKey: \PekingA, noteKey: \66)).put(\rate, 1).postln.play;

VGSamp.eventFor((instKey: \PekingA, noteKey: \66)).put(\rate, 0.9).postln.play;


// for sketch retuning by lookup; better lokup scheme to be written later:

(

Pdefn(\tunePekingA, Pfunc({ |ev| ().at(ev.noteKey) ? 1 }));

Pdef(\pekingA,

Pbind(

\laras, \slendro,

\instKey, \PekingA, 

\noteKey, Pseq([\56, \61, \62, \63], inf), 

\amp, 0.5,

\pan, -1, 

\rate, Pdefn(\tunePekingA),

\samp, Pfunc({ |ev| ev.putAll(VGSamp.eventFor(ev)); \vgsamp }),

\dur, 0.5

)).play;

)

// + 20 cents for \56

Pdefn(\tunePekingA, Pfunc({ |ev| ('56': (20/100).midiratio).at(ev.noteKey).postln ? 1 }));


// + 40 cents for \56

Pdefn(\tunePekingA, Pfunc({ |ev| ('56': (40/100).midiratio).at(ev.noteKey).postln ? 1 }));


// + 60 cents

Pdefn(\tunePekingA, Pfunc({ |ev| ('56': (60/100).midiratio).at(ev.noteKey).postln ? 1 }));


// no retuning again

Pdefn(\tunePekingA, Pfunc({ |ev| ().at(ev.noteKey).postln ? 1 }));



/*********************** extra info, more low level tests ***********************/


// More lookup examples:


VGSamp.keyFor(\PekingA, \66); // pelog by default

VGSamp.keyFor(\PekingA, \66, \slendro);

VGSamp.keyFor(\KendhangGdh, \bem, \neutral);



// a utility to listen to individual samples:

x = VGSamp.play(\Kenong, \43);

x.release(0.1); // and to stop it



// or you can also use the synthdefname : 

x = Synth("vgsamp1", [\bufnum, 13, \amp, 1, \pan, -0.5]); 

x.release;


/**** the synthdefs params are: 

\out - [0, 1, 2 .. the output bus channel to play on (0 unless multichannel playback). 

\amp - 0.0 - 1.0  samples are not leveled equally yet]. 

\pan -  -1.0 - 1.0 stereo panning 

\bufnum - the numberID (bufnum) of the buffer that contains 

that sample in VGSamp.bufenv. 

\gate - 0, 1 setting to 0 releases the playback

****/

// some more background on how things work:



VGSamp.verbose; // determines whether VGSamp posts info or not.

VGSamp.verbose_(false); // is quiet

VGSamp.verbose_(true); // is verbose (this is default).



VGSamp.defaultDir; // where Gamelan samples folder should be!

VGSamp.instGroups.postcs; // insts are organized in groups.

VGSamp.instsDict.postcs; ""; // where the raw instrument infos live

VGSamp.filesDict.postcs; ""; // where file/bufnum are looked up

VGSamp.makeSynDef; // store the synthdef for VGSamp.


// if you want to keep the samples in some specific place, do this:

// VGSamp.dir_("myGamelanFolder/wav_files/");

// VGSamp.dir_("/MyDisk/someFolder/gamelanStuff/gamKUG_wavs/");



// this is how lookups work:

VGSamp.keyFor(\Kenong, \43); // return buffername for an istr and note

VGSamp.keyFor(\Kenong, \12); // complains if note is not there ...

VGSamp.keyFor(\piano, \43); // and if instrument is not there.


// samples are loaded in buffers and accessible by name;

VGSamp.bufenv[\Sl_Kenong_43];

VGSamp.eventFor((instKey: \Kerploing, noteKey: \51)).play;



/********* TO DO ******


support global bus on VGSamp: 

syndef should read globalbus and instr bus. 

global gbus: tune, amp, ignore ringtime, out, rev ... 

instr  ibus: tune, amp, ignore ringtime, out, rev ...

get global pan into evnetFor ... 

then samples can be retuned, 

panned and played out of different channels. 

***********************/