[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] SF.net SVN: quarks:[2834] wslib/wslib-classes/Extensions/Various/ extSynthdef-record.sc



Revision: 2834
          http://sourceforge.net/p/quarks/code/2834
Author:   wsnoei
Date:     2021-01-19 10:06:26 +0000 (Tue, 19 Jan 2021)
Log Message:
-----------
remove OSCresponder in Function:loadToBuffer

Modified Paths:
--------------
    wslib/wslib-classes/Extensions/Various/extSynthdef-record.sc

Modified: wslib/wslib-classes/Extensions/Various/extSynthdef-record.sc
===================================================================
--- wslib/wslib-classes/Extensions/Various/extSynthdef-record.sc	2021-01-18 15:48:15 UTC (rev 2833)
+++ wslib/wslib-classes/Extensions/Various/extSynthdef-record.sc	2021-01-19 10:06:26 UTC (rev 2834)
@@ -1,91 +1,104 @@
-// wslib 2005
-//
-// writing functions to buffers and synths to files
-
-+ Function {
-	// directly write functions to soundfiles (realtime)
-	// args is am aray, a msg style array of arguments for the function or a dict:
-	//   [440, 1] or [\freq, 440, \gate 1] or (freq: 440, gate: 1)
-	// 
-	// based on Function-loadToFloatArray
-	
-	loadToBuffer { arg duration = 1, server, action, bufnum, args;
-		var buffer, def, synth, value, name, numChannels;
-		server = server ? Server.default;
-		server.isLocal.not.if({"Function-loadToBuffer only works with a localhost server".warn; 
-			^nil });
-		server.serverRunning.not.if({"Server not running!".warn; ^nil });
-		if(args.notNil) 
-			{ value = this.value(*args)}
-			{ value = this.value };
-		if(value.size == 0, { numChannels = 1 }, { numChannels =  value.size });
-		buffer = Buffer.new(server, duration * server.sampleRate, numChannels, bufnum);
-		// no need to check for rate as RecordBuf is ar only
-		name = name ? this.hash.asString;
-		def = SynthDef(name, { 
-			RecordBuf.ar(
-				( if(args.notNil) 
-			{ this.valueArgsArray(args)}
-			{ this.value } ),  buffer.bufnum, loop:0);
-			Line.ar(dur: duration, doneAction: 2);
-		});
-		Routine.run({
-			var c;
-			c = Condition.new;
-			server.sendMsgSync(c, *buffer.allocMsg);
-			server.sendMsgSync(c, "/d_recv", def.asBytes);
-			synth = Synth.basicNew(name, server);
-			if(action.notNil)
-				{ OSCpathResponder(server.addr, ['/n_end', synth.nodeID], { 
-				 action.value(buffer);
-			}).add.removeWhenDone; };
-			server.listSendMsg(synth.newMsg);
-		});
-		^buffer;
-	}
-	
-	write { arg duration = 1, path, headerFormat="aiff",sampleFormat="int24", args;
-		if( {path.splitext.last[..2]}.try != headerFormat[..2])
-				{ path = [path.splitext.first, headerFormat].join(".");
-				("Extension mismatch:\nchanged filename to: " ++ path.basename).postln };
-		this.loadToBuffer(duration, args: args,
-			action: { |buffer| buffer.write(path, headerFormat, sampleFormat, 
-				completionMessage: {
-					("done writing :\n" ++ path.asCompileString).postln; buffer.freeMsg;  }) });
-		^this;
-		}
-		
-	writeDialog { arg duration = 1, headerFormat="aiff",sampleFormat="int24", args;
-		CocoaDialog.savePanel( { |path|
-			this.write(duration, path, headerFormat, sampleFormat, args);
-		});
-		^this;
-		}
+{\rtf1\ansi\ansicpg1252\cocoartf1671\cocoasubrtf600
+\cocoascreenfonts1{\fonttbl\f0\fnil\fcharset0 Monaco;}
+{\colortbl;\red255\green255\blue255;\red191\green0\blue0;\red0\green0\blue0;\red0\green0\blue191;
+\red0\green0\blue255;\red96\green96\blue96;\red51\green51\blue191;\red102\green102\blue191;\red0\green115\blue0;
 }
-
-+ Buffer {
-	*loadFunction { |function, duration, bufnum|
-		^function.loadToBuffer(duration, nil, bufnum) }
+{\*\expandedcolortbl;;\csgenericrgb\c75000\c0\c0;\csgenericrgb\c0\c0\c0;\csgenericrgb\c0\c0\c75000;
+\csgenericrgb\c0\c0\c100000;\csgenericrgb\c37500\c37500\c37500;\csgenericrgb\c20000\c20000\c75000;\csgenericrgb\c40000\c40000\c75000;\csgenericrgb\c0\c45000\c0;
 }
+\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural
 
-+ SynthDef {
-	// just a wrapper for Function-write
-	// resembles the SC2 "Synth.record"
-	// creates a standard synthdef, which is NOT the one used for writing
-	// name is used for filename
-	// make sure that the function returns the audiorate output, not an Out, 
-	// or it will not record anything.
-	*record { arg name, ugenGraphFunc, duration = 1, addPath = "sounds/", 
-				headerFormat="aiff",sampleFormat="int24";
-		ugenGraphFunc.write(duration, 
-			(addPath ++ name ++ "." ++ headerFormat).standardizePath,
-				 headerFormat, sampleFormat);
-		^SynthDef(name, ugenGraphFunc);
-		}
-		
-	*recordDialog { arg name, ugenGraphFunc, duration = 1, 
-			headerFormat="aiff", sampleFormat="int24";
-		ugenGraphFunc.writeDialog(duration, headerFormat, sampleFormat);
-		^SynthDef(name, ugenGraphFunc);
-		}
-	}
+\f0\fs20 \cf2 // wslib 2005\cf3 \
+\cf2 //\cf3 \
+\cf2 // writing functions to buffers and synths to files\cf3 \
+\
++ \cf4 Function\cf3  \{\
+	\cf2 // directly write functions to soundfiles (realtime)\cf3 \
+	\cf2 // args is am aray, a msg style array of arguments for the function or a dict:\cf3 \
+	\cf2 //   [440, 1] or [\\freq, 440, \\gate 1] or (freq: 440, gate: 1)\cf3 \
+	\cf2 // \cf3 \
+	\cf2 // based on Function-loadToFloatArray\cf3 \
+	\
+	loadToBuffer \{ \cf5 arg\cf3  duration = 1, server, action, bufnum, args;\
+		\cf5 var\cf3  buffer, def, synth, value, name, numChannels;\
+		server = server ? \cf4 Server\cf3 .default;\
+		server.isLocal.not.if(\{\cf6 "Function-loadToBuffer only works with a localhost server"\cf3 .warn; \
+			^\cf7 nil\cf3  \});\
+		server.serverRunning.not.if(\{\cf6 "Server not running!"\cf3 .warn; ^\cf7 nil\cf3  \});\
+		if(args.notNil) \
+			\{ value = \cf8 this\cf3 .value(*args)\}\
+			\{ value = \cf8 this\cf3 .value \};\
+		if(value.size == 0, \{ numChannels = 1 \}, \{ numChannels =  value.size \});\
+		buffer = \cf4 Buffer\cf3 .new(server, duration * server.sampleRate, numChannels, bufnum);\
+		\cf2 // no need to check for rate as RecordBuf is ar only\cf3 \
+		name = name ? \cf8 this\cf3 .hash.asString;\
+		def = \cf4 SynthDef\cf3 (name, \{ \
+			\cf4 RecordBuf\cf3 .ar(\
+				( if(args.notNil) \
+			\{ \cf8 this\cf3 .valueArgsArray(args)\}\
+			\{ \cf8 this\cf3 .value \} ),  buffer.bufnum, loop:0);\
+			\cf4 Line\cf3 .ar(dur: duration, doneAction: 2);\
+		\});\
+		\cf4 Routine\cf3 .run(\{\
+			\cf5 var\cf3  c;\
+			c = \cf4 Condition\cf3 .new;\
+			server.sendMsgSync(c, *buffer.allocMsg);\
+			server.sendMsgSync(c, \cf6 "/d_recv"\cf3 , def.asBytes);\
+			synth = \cf4 Synth\cf3 .basicNew(name, server);\
+			if (action.notNil) \{\
+				\cf4 OSCFunc\cf3 (\{ action.value(buffer) \},\
+					\cf9 '/n_end'\cf3 , server.addr,\
+					argTemplate: [synth.nodeID]\
+				).oneShot\
+			\};\
+			server.listSendMsg(synth.newMsg);\
+		\});\
+		^buffer;\
+	\}\
+	\
+	write \{ \cf5 arg\cf3  duration = 1, path, headerFormat=\cf6 "aiff"\cf3 ,sampleFormat=\cf6 "int24"\cf3 , args;\
+		if( \{path.splitext.last[..2]\}.try != headerFormat[..2])\
+				\{ path = [path.splitext.first, headerFormat].join(\cf6 "."\cf3 );\
+				(\cf6 "Extension mismatch:\\nchanged filename to: "\cf3  ++ path.basename).postln \};\
+		\cf8 this\cf3 .loadToBuffer(duration, args: args,\
+			action: \{ \cf5 |buffer|\cf3  buffer.write(path, headerFormat, sampleFormat, \
+				completionMessage: \{\
+					(\cf6 "done writing :\\n"\cf3  ++ path.asCompileString).postln; buffer.freeMsg;  \}) \});\
+		^\cf8 this\cf3 ;\
+		\}\
+		\
+	writeDialog \{ \cf5 arg\cf3  duration = 1, headerFormat=\cf6 "aiff"\cf3 ,sampleFormat=\cf6 "int24"\cf3 , args;\
+		\cf4 CocoaDialog\cf3 .savePanel( \{ \cf5 |path|\cf3 \
+			\cf8 this\cf3 .write(duration, path, headerFormat, sampleFormat, args);\
+		\});\
+		^\cf8 this\cf3 ;\
+		\}\
+\}\
+\
++ \cf4 Buffer\cf3  \{\
+	*loadFunction \{ \cf5 |function, duration, bufnum|\cf3 \
+		^function.loadToBuffer(duration, \cf7 nil\cf3 , bufnum) \}\
+\}\
+\
++ \cf4 SynthDef\cf3  \{\
+	\cf2 // just a wrapper for Function-write\cf3 \
+	\cf2 // resembles the SC2 "Synth.record"\cf3 \
+	\cf2 // creates a standard synthdef, which is NOT the one used for writing\cf3 \
+	\cf2 // name is used for filename\cf3 \
+	\cf2 // make sure that the function returns the audiorate output, not an Out, \cf3 \
+	\cf2 // or it will not record anything.\cf3 \
+	*record \{ \cf5 arg\cf3  name, ugenGraphFunc, duration = 1, addPath = \cf6 "sounds/"\cf3 , \
+				headerFormat=\cf6 "aiff"\cf3 ,sampleFormat=\cf6 "int24"\cf3 ;\
+		ugenGraphFunc.write(duration, \
+			(addPath ++ name ++ \cf6 "."\cf3  ++ headerFormat).standardizePath,\
+				 headerFormat, sampleFormat);\
+		^\cf4 SynthDef\cf3 (name, ugenGraphFunc);\
+		\}\
+		\
+	*recordDialog \{ \cf5 arg\cf3  name, ugenGraphFunc, duration = 1, \
+			headerFormat=\cf6 "aiff"\cf3 , sampleFormat=\cf6 "int24"\cf3 ;\
+		ugenGraphFunc.writeDialog(duration, headerFormat, sampleFormat);\
+		^\cf4 SynthDef\cf3 (name, ugenGraphFunc);\
+		\}\
+	\}\
+}
\ No newline at end of file

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


_______________________________________________
sc-dev mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-dev/
search: https://listarc.bham.ac.uk/lists/sc-dev/search/