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

[sc-dev] SF.net SVN: quarks:[2666]



Revision: 2666
          http://sourceforge.net/p/quarks/code/2666
Author:   decampo
Date:     2013-12-20 00:24:39 +0000 (Fri, 20 Dec 2013)
Log Message:
-----------
update to schelp.

Modified Paths:
--------------
    Republic/classes/extras/Shout.sc

Added Paths:
-----------
    Morse/HelpSource/
    Morse/HelpSource/Classes/
    Morse/HelpSource/Classes/Morse.schelp
    Morse/HelpSource/Classes/MorseDict.schelp

Added: Morse/HelpSource/Classes/Morse.schelp
===================================================================
--- Morse/HelpSource/Classes/Morse.schelp	                        (rev 0)
+++ Morse/HelpSource/Classes/Morse.schelp	2013-12-20 00:24:39 UTC (rev 2666)
@@ -0,0 +1,195 @@
+TITLE:: Morse
+summary:: create time patterns based on Morse code.
+categories:: HistoricalCommunication
+related:: MorseDict
+
+DESCRIPTION::
+Morse looks dot-dash patterns (in MorseDict) for a given character or string
+and converts them to times for playback. Based on the Morse class by Hairi Vogel.
+
+http://en.wikipedia.org/wiki/Morse_Code,
+based on ITU recommendation ITU-R M.1677, found here:
+http://www.godfreydykes.info/international\ morse\ code.pdf
+
+code::
+	Morse.signs($a);
+	Morse.timesFor($a); // dot - pause - dash - pause
+
+	Morse.signs("SOS");
+	Morse.word("SOS");
+
+    Morse("Hello Morse");
+	Morse.signs("SOS SOS");
+::
+
+
+CLASSMETHODS::
+
+METHOD:: timesFor
+get the times for a single character or symbol.
+ARGUMENT:: char
+ a single char or one of the supported special symbols.
+returns:: a list of dot-dash time values and the pauses in between them.
+
+code::
+	Morse.timesFor($a);
+
+// ->	[ 0.1, 0.1, 0.3, 0.3 ]
+	  dot (inside-char pause) dash (inside-word pause)
+::
+
+METHOD:: word
+get the time lists for a word.
+ARGUMENT:: word
+a string without blank space
+returns:: the time values for the chars in the word.
+
+code::
+	Morse.word("SOS").printAll;
+
+	[ 0.1, 0.1, 0.1, 0.1, 0.1, 0.3 ]
+	  di        di        dit
+	[ 0.3, 0.1, 0.3, 0.1, 0.3, 0.3 ]
+	  dah       dah       dah
+	[ 0.1, 0.1, 0.1, 0.1, 0.1, 0.7 ]
+	  di        di        dit  (pause between words)
+::
+
+METHOD:: new
+get the time lists for a word.
+ARGUMENT:: text
+the text to be encoded to Morse times. default = "Hello Morse".
+returns:: the time values for the text
+
+METHOD:: signs
+convert a text to dot-dash signs.
+ARGUMENT:: text
+the text to be encoded to Morse dot-dash signs. default = "Hello Morse"
+returns:: the time values for the text
+
+METHOD:: dot
+get and set the time for a dot - default is 0.1
+
+METHOD:: dash
+get and set the time for a dash - default is 0.3
+
+METHOD:: intra
+get and set pause time within a char - default is 0.1
+
+METHOD:: short
+get and set pause time between chars - default is 0.3
+
+METHOD:: medium
+get and set pause time between words - default is 0.7
+
+METHOD:: verbose
+get and set flag whether to post debug messages
+
+
+code::
+z = "Morse Code";
+Morse(z).postln.flat;
+
+	// post the times for z in time:
+(
+Tdef(\morse, { var times;
+	times = Morse(z).flat;
+	(times.flat * 0.5).do({ arg time, i;
+		time.postln.wait;
+	});
+}).play;
+)
+
+// example with JITLib
+
+Ndef(\morse, { arg amp = 0; SinOsc.ar(600, 0, amp * 0.2); }).play;
+
+Ndef(\morse).set(\amp, 1);
+Ndef(\morse).set(\amp, 0);
+(
+Tdef(\morse, {
+	var times;
+	Ndef(\morse).play;
+	times = Morse(z).postln.flat;
+	(times.flat * 0.5).do({ arg time, i;
+		Ndef(\morse).set(\amp, [ 1, 0 ].wrapAt(i));
+		time.wait;
+	});
+});
+)
+
+
+z = "Code";	Tdef(\morse).play; // z is the text to play.
+
+Tdef(\morse).stop.play;	// repeat
+
+z = "Cheers Hairi";
+Tdef(\morse).stop.play;
+
+
+	// gate any running sound with morse.
+
+Ndef(\src, { FSinOsc.ar(600, 0, 0.2); });
+
+Ndef(\morse).set(\amp, 0);
+
+Ndef(\morse, { arg amp = 0.0; Ndef(\src).ar * amp });
+Ndef(\morse).play;
+
+Ndef(\src).stop
+Ndef(\src).fadeTime = 5;
+
+	// and change source while playing:
+z = "Try Alternative Beeps Yourself";		// new text.
+Tdef(\morse).stop.play;	// start over
+
+Ndef(\src, { SinOsc.ar(LFNoise1.kr([0.3, 0.31], 200, 800)).sum });
+
+Ndef(\src).play
+Ndef(\src).stop
+
+Tdef(\morse).stop.play;	// start over
+Ndef(\src, { LPF.ar(Saw.ar(LFNoise1.kr([0.3, 0.31], 200, 800)), 2000).sum * 0.5 });
+
+Tdef(\morse).stop.play;	// start over
+Ndef(\src, { Impulse.ar(LFNoise1.kr([0.3, 0.31], 200, 800)).sum.lag(0.001) * LFPulse.ar(80, 0, LFNoise1.kr(1, 0.5, 0.5)) });
+
+~out.set(\amp, 0.2);
+~out.set(\amp, 0);
+
+Ndef(\src, { GrayNoise.ar(1, 1) * SinOsc.ar(600) * 0.2 });
+
+
+(
+Tdef(\morse, {
+	var times;
+	Ndef(\morse).play;
+	times = Morse(z).postln.flat;
+	(times.flat * 0.3).do({ arg time, i;
+		Ndef(\morse).set(\amp, [ 1, 0 ].wrapAt(i));
+		time.wait;
+	});
+});
+)
+
+
+	// the test word for Morse transmission speed definition:
+Morse("Paris").flat.sum;
+
+	// 5 secs means it could be transmitted 12 times in one minute;
+	// so this speed is 12 words per minute, or WPM.
+
+
+(
+z = "Paris";
+Tdef(\morse, {
+	var times;
+	Ndef(\morse).play;
+	times = Morse(z).postln.flat;
+	(times.flat).do({ arg time, i;
+		Ndef(\morse).set(\amp, [ 1, 0 ].wrapAt(i));
+		time.wait;
+	});
+}).play;
+)
+::

Added: Morse/HelpSource/Classes/MorseDict.schelp
===================================================================
--- Morse/HelpSource/Classes/MorseDict.schelp	                        (rev 0)
+++ Morse/HelpSource/Classes/MorseDict.schelp	2013-12-20 00:24:39 UTC (rev 2666)
@@ -0,0 +1,77 @@
+TITLE:: MorseDict
+summary:: a dictionary of Morse code signs.
+categories:: HistoricalCommunication
+related:: Classes/Morse
+
+DESCRIPTION::
+MorseDict is used by the Morse class to look up Morse symbols as defined in the standard Morse alphabet.
+It can do several kinds of lookups and conversions which may be useful for different
+
+code::
+	// Tests for MorseDict:
+MorseDict.keys.postcs; // all supported morse keys
+MorseDict.postKeys; // post
+MorseDict.codes;  // numerical codes for each key
+MorseDict.strings;  // strings used for display
+
+// lookup methods for signs and codes
+MorseDict.signs($a).postcs;
+MorseDict.signs('error').postcs;
+MorseDict.at($a);
+MorseDict.at('error');
+
+// for words and texts
+MorseDict.wordSigns("abc").postcs
+MorseDict.wordSigns("abc def gh").postcs
+MorseDict.wordSigns("&%!#").postcs
+MorseDict.wordSigns([$a, $b, $c, 'endOfWork']).postcs
+
+// reverse lookup - get chars or symbols for signs
+MorseDict.letters;
+MorseDict.letter('.'); // e == dot
+MorseDict.letter('..'); // i == dot dot
+MorseDict.letter('---'); // o == dash dash dash
+
+::
+
+
+CLASSMETHODS::
+
+METHOD:: keys
+all keys that are defined in the Morse alphabet.
+
+METHOD:: postKeys
+a convenience method to post all keys.
+
+METHOD:: strings
+the strings used to transliterate dot, dash, word break.
+
+METHOD:: codes
+the dict of all dot-and-dash patterns corresponding to each key in the Morse alphabet. E.g. the pattern for $a is dot-dash, encoded here as [0, 1].
+
+METHOD:: signs
+get the signs for a single character or symbol
+
+ARGUMENT:: char
+the char to look up
+
+METHOD:: wordSigns
+get the sequence of signs for a word or text
+ARGUMENT:: word
+a string or sequence of chars and symbols
+
+METHOD:: at
+look up code for single char or symbol
+ARGUMENT:: code
+a single char or symbol as defined in the keys
+
+METHOD:: fromAscii
+same as at method
+
+METHOD:: letters
+lookup dict from dot-dash patterns to characters or symbols
+
+METHOD:: letter
+look up the corresponding letter or symbol for a given dot-dash code.
+ARGUMENT:: code
+a string of dots and dashes.

Modified: Republic/classes/extras/Shout.sc
===================================================================
--- Republic/classes/extras/Shout.sc	2013-12-19 22:56:59 UTC (rev 2665)
+++ Republic/classes/extras/Shout.sc	2013-12-20 00:24:39 UTC (rev 2666)
@@ -1,56 +1,56 @@
 
 Shout {
 	classvar <win, <txtView, <>tag="//!!";
-	classvar <>width=1250, <shouts, <codeDumpFunc; 
-	
+	classvar <>width=1250, <shouts, <codeDumpFunc;
+
 	classvar <>rect;
-	
-	*initClass { 
-		shouts = List.new; 
+
+	*initClass {
+		shouts = List.new;
 		codeDumpFunc = { |str| if (str.beginsWith(Shout.tag)) { Shout(str.drop(Shout.tag.size)) } };
 		rect = Rect(0, 0, 1024, 80);
 	}
 
-	*makeWin { |message="Shout this!"| 
-	
+	*makeWin { |message="Shout this!"|
+
 		win = Window("Shout'er", rect).front;
 		win.alpha_(0.7);
 		win.view.background_(Color.clear);
 		win.alwaysOnTop_(true);
-		
+
 		txtView = TextView(win, win.bounds.moveTo(0,0));
 		txtView.background_(Color.clear);
 		txtView.font_(Font("Monaco", 32));
 		txtView.resize_(2);
-		
+
 		width = rect.width;
-		
+
 		this.setMessage(message);
 	}
 
-		// simple versions of methods, for sc-book chapter 
-//	*setMessage { |message| 
+		// simple versions of methods, for sc-book chapter
+//	*setMessage { |message|
 //		txtView.string_(message.asString)
 //	}
-	
-//	*new { |message="\xC1Shout'er!"| 
+
+//	*new { |message="�Shout'er!"|
 //		shouts.add(message);
 //
-//		if (win.isNil or: { win.isClosed }) { 
-//			this.makeWin(message); 
+//		if (win.isNil or: { win.isClosed }) {
+//			this.makeWin(message);
 //		} {
 //			this.setMessage(message);
 //		};
 //	}
 
-	*new { |message="\xC1Shout'er!"| 
+	*new { |message="�Shout'er!"|
 		var currDoc;
 		shouts.add(message);
 
-		if (win.isNil or: { win.isClosed }) { 
+		if (win.isNil or: { win.isClosed }) {
 			currDoc = Document.current;
-			Task { 
-				this.makeWin(message); 
+			Task {
+				this.makeWin(message);
 				0.1.wait;
 				currDoc.front;
 			}.play(AppClock);
@@ -59,11 +59,11 @@
 		};
 	}
 
-	*setMessage { |message| 
+	*setMessage { |message|
 		var messSize, fontSize;
 		messSize = message.size;
-		
-		defer { 
+
+		defer {
 			fontSize = (1.64 * txtView.bounds.width) / max(messSize, 32);
 			txtView.font_(Font("Monaco", fontSize))
 				.string_(message.asString);
@@ -72,30 +72,30 @@
 	}
 
 	*animate { |dt=0.2, n=12|
-		var colors = [Color.red, Color.green, Color.blue]; 
-		Task { 
-			n.do { |i| 
-				try { 
-					txtView.stringColor_(colors.wrapAt(i)); 
-					dt.wait 
+		var colors = [Color.red, Color.green, Color.blue];
+		Task {
+			n.do { |i|
+				try {
+					txtView.stringColor_(colors.wrapAt(i));
+					dt.wait
 				}
 			};
 			try { txtView.stringColor_(Color.red) }; // make sure we end red
 		}.play(AppClock);
 	}
 
-	*add { var interp = thisProcess.interpreter; 
-		interp.codeDump = interp.codeDump.addFunc(codeDumpFunc); 
+	*add { var interp = thisProcess.interpreter;
+		interp.codeDump = interp.codeDump.addFunc(codeDumpFunc);
 	}
-	*remove { var interp = thisProcess.interpreter; 
-		interp.codeDump = interp.codeDump.removeFunc(codeDumpFunc); 
+	*remove { var interp = thisProcess.interpreter;
+		interp.codeDump = interp.codeDump.removeFunc(codeDumpFunc);
 	}
 
-} 
+}
 /* Tests
 Shout("We should consider stopping...me fkjdfgkfjdgkjfdhkgjf")
 Shout("We should consider stopping...")
-Shout("\xC1Hey Hey Hey Na na na!");
+Shout("�Hey Hey Hey Na na na!");
 
 Shout.add;
 //!! does this show up
@@ -103,6 +103,6 @@
 //!! does this show up
 
 // 	for pbup setup use, add to Oscresponder(nil, '/share' ...) :
-	if (str.beginsWith(Shout.tag)) { Shout(str.drop(Shout.tag.size) + "-" ++ msg[1]) }; 
-	
+	if (str.beginsWith(Shout.tag)) { Shout(str.drop(Shout.tag.size) + "-" ++ msg[1]) };
+
 */

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.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-dev/
search: https://listarc.bham.ac.uk/lists/sc-dev/search/