diff yeti/templates.yeti @ 13:e15bc63cb146

Ranges, EM initialisation
author Chris Cannam
date Fri, 21 Mar 2014 18:12:38 +0000
parents 0f6db1895e1c
children a91de434feb8
line wrap: on
line diff
--- a/yeti/templates.yeti	Fri Mar 21 17:14:44 2014 +0000
+++ b/yeti/templates.yeti	Fri Mar 21 18:12:38 2014 +0000
@@ -2,6 +2,7 @@
 module templates;
 
 vec = load may.vector;
+mat = load may.matrix;
 
 // Load instrument templates
 
@@ -22,14 +23,24 @@
     do instrument:
         readFile "../data/\(instrument).csv" "UTF-8"
             do istr:
-                array
+                mat.fromColumns
                    (map do line:
                         vec.fromList (map number (strSplit "," line))
-                   done (istr.lines ()));
+                    done (istr.lines ()));
             done;
     done instruments;
 
+//!!! these ranges are hardcoded in the original (and are a bit more restrictive)
+extractRanges templates = mapIntoHash id
+    do instrument:
+        levels = map vec.sum (mat.asColumns (templates[instrument]));
+        first = length levels - length (find (>0) levels);
+        last = length (find (>0) (reverse levels)) - 1;
+        { lowestNote = first, highestNote = last }
+    done (keys templates);
+
 {
-    loadTemplates
+    loadTemplates,
+    extractRanges
 }