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

[sc-dev] SF.net SVN: quarks:[2655] wslib/wslib-classes



Revision: 2655
          http://sourceforge.net/p/quarks/code/2655
Author:   wsnoei
Date:     2013-11-03 12:18:06 +0000 (Sun, 03 Nov 2013)
Log Message:
-----------
change String:fill and String:collect overwrites, enable SimpleMIDIFile playback based on ticks instead of seconds

Modified Paths:
--------------
    wslib/wslib-classes/Extensions/String/extString-collection.sc
    wslib/wslib-classes/Lang/Improvements/extString-collect.sc
    wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-patterns.sc

Modified: wslib/wslib-classes/Extensions/String/extString-collection.sc
===================================================================
--- wslib/wslib-classes/Extensions/String/extString-collection.sc	2013-10-22 16:48:55 UTC (rev 2654)
+++ wslib/wslib-classes/Extensions/String/extString-collection.sc	2013-11-03 12:18:06 UTC (rev 2655)
@@ -3,10 +3,9 @@
 // conversion String <-> SequenceableCollection
 
 + SequenceableCollection {
-	toString { ^String.fill(this.size, { |i| 
-		if(this[i].notNil) {this[i]} {" "} }) }
-	asAscii {  ^String.fill(this.size, { |i| {this[i].asInteger.asAscii}.try ? "" }) } 
-	asDigit {  ^String.fill(this.size, { |i| {this[i].asInteger.asDigit}.try ? "" }) }
+	toString { ^this.collect(_ ? " ").join }
+	asAscii {  ^this.collect({|x| {x.asInteger.asAscii}.try ? "" }).join } 
+	asDigit {  ^this.collect({|x| {x.asInteger.asDigit}.try ? "" }).join }
 	
 }
 

Modified: wslib/wslib-classes/Lang/Improvements/extString-collect.sc
===================================================================
--- wslib/wslib-classes/Lang/Improvements/extString-collect.sc	2013-10-22 16:48:55 UTC (rev 2654)
+++ wslib/wslib-classes/Lang/Improvements/extString-collect.sc	2013-11-03 12:18:06 UTC (rev 2655)
@@ -4,36 +4,37 @@
 	
 	// general flexibility improvements:
 	
-	collect { | function | 
-		// this changes functionality of some other methods (like .tr) too
-		var result = "";
-		this.do {|elem, i| result = result ++ function.value(elem, i); }
-		^result;
-		}
-		
-	*fill { | size, function | // any output for function is accepted
-		var obj = "";
-		size.do { | i | obj = obj ++ function.value(i); };
-		^obj
+	collectJoin { | function, joiner | 
+		^this.collectAs( function, Array ).join( joiner );
 	}
+	
+	*fillJoin { | size, function, joiner, excludeNil = true | // any output for function is accepted
+		var array;
+		array = Array.fill( size, function );
+		if( excludeNil ) { array = array.select(_.notNil) };
+		^array.join( joiner )
+	}
 
 	removeItems { |items = "\n\t"| // defaults to removing returns and tabs
 		// !! not in place !!
 		items = items.asString;
-		^this.collect({ |char| if( items.includes(char) ) {""} {char} });
-		}
+		^this.collectJoin({ |char| if( items.includes(char) ) {""} {char} });
+	}
+	
 	replaceItems { |items = "\n\t", replaceWith = "  "| 
 		// !! not in place !!
 		// replaceWith can also be array of strings
 		// similar to tr, but replaces multiple chars
 		// "hello".replaceItems("ho", ["oh h",$!])
-		^this.collect({ |char|
+		^this.collectJoin({ |char|
 			var index = items.indexOf(char);
-			if( index.notNil )
-				{ replaceWith[index] }
-				{ char }
-			});
-		}
+			if( index.notNil ) { 
+				replaceWith[index] 
+			} { 
+				char 
+			}
+		});
+	}
 		
 	// shortcuts:
 	

Modified: wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-patterns.sc
===================================================================
--- wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-patterns.sc	2013-10-22 16:48:55 UTC (rev 2654)
+++ wslib/wslib-classes/Main Features/SimpleMIDIFile/extSimpleMIDIFile-patterns.sc	2013-11-03 12:18:06 UTC (rev 2655)
@@ -1,14 +1,20 @@
 + SimpleMIDIFile {
 	
-	p { |inst, amp = 0.2| // amp: amp when velo == 127
+	p { |inst, amp = 0.2, useTempo = true| // amp: amp when velo == 127
 		var thisFile;
 		inst = ( inst ? 'default' ).asCollection;
 		
 		// todo: create multi-note events from chords, detect rests
 		
-		if( timeMode == 'seconds' )
-			{ thisFile = this }
-			{ thisFile = this.copy.timeMode_( 'seconds' ); };
+		if( useTempo ) {
+			if( timeMode == 'seconds' )
+				{ thisFile = this }
+				{ thisFile = this.copy.timeMode_( 'seconds' ); };
+		} {
+			if( timeMode == 'ticks' )
+				{ thisFile = this }
+				{ thisFile = this.copy.timeMode_( 'ticks' ); };
+		};
 		 ^Ppar(
 			({ |tr|
 				var sustainEvents, deltaTimes;
@@ -16,7 +22,13 @@
 				if( sustainEvents.size > 0 )
 					{ 
 					sustainEvents = sustainEvents.flop;
-					deltaTimes = sustainEvents[1].differentiate;
+					if( useTempo ) {
+						deltaTimes = sustainEvents[1].differentiate;
+					} {
+						// always use 120BPM
+						deltaTimes = (sustainEvents[1] / (division*2)).differentiate;
+						sustainEvents[6] = sustainEvents[6] / (division*2);
+					};
 					Pbind(
 						\instrument, inst.wrapAt( tr + 1 ),
 						\dur, Pseq( deltaTimes ++ [0], 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/