Created
January 21, 2022 21:30
-
-
Save santolucito/f70a616e248e6bc35d5de5b251f00bc2 to your computer and use it in GitHub Desktop.
MaxMSP CSV Processor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//read in a csv on initialization of object | |
//automatically set num of outlets based on num of columns in csv | |
//send value of each column out of the respective outlet index on a bang | |
//outlet values are all strings | |
var csv_filename = ""; | |
if (jsarguments.length>1) | |
csv_filename = jsarguments[1]; | |
var f = new File(csv_filename) | |
var data = f.readline() | |
var numColumns = data.split(",").length | |
outlets = numColumns | |
function bang() | |
{ | |
if (!f.isopen) { | |
error("could not open file:" + csv_filename) | |
return | |
} | |
if (f.position >= f.eof) { | |
//reached end of file, looping back to start of file | |
//set file pos to 0, then read in header line | |
f.position = 0 | |
f.readline() | |
} | |
data = f.readline() | |
var parsedData = data.split(",") | |
parsedData.forEach( function(columnValue, i) { | |
outlet(i,columnValue.trim()); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"patcher" : { | |
"fileversion" : 1, | |
"appversion" : { | |
"major" : 8, | |
"minor" : 1, | |
"revision" : 11, | |
"architecture" : "x64", | |
"modernui" : 1 | |
} | |
, | |
"classnamespace" : "box", | |
"rect" : [ 691.0, 201.0, 415.0, 480.0 ], | |
"bglocked" : 0, | |
"openinpresentation" : 0, | |
"default_fontsize" : 12.0, | |
"default_fontface" : 0, | |
"default_fontname" : "Arial", | |
"gridonopen" : 1, | |
"gridsize" : [ 15.0, 15.0 ], | |
"gridsnaponopen" : 1, | |
"objectsnaponopen" : 1, | |
"statusbarvisible" : 2, | |
"toolbarvisible" : 1, | |
"lefttoolbarpinned" : 0, | |
"toptoolbarpinned" : 0, | |
"righttoolbarpinned" : 0, | |
"bottomtoolbarpinned" : 0, | |
"toolbars_unpinned_last_save" : 0, | |
"tallnewobj" : 0, | |
"boxanimatetime" : 200, | |
"enablehscroll" : 1, | |
"enablevscroll" : 1, | |
"devicewidth" : 0.0, | |
"description" : "", | |
"digest" : "", | |
"tags" : "", | |
"style" : "", | |
"subpatcher_template" : "", | |
"assistshowspatchername" : 0, | |
"boxes" : [ { | |
"box" : { | |
"id" : "obj-11", | |
"linecount" : 3, | |
"maxclass" : "comment", | |
"numinlets" : 1, | |
"numoutlets" : 0, | |
"patching_rect" : [ 30.5, 38.0, 266.0, 48.0 ], | |
"text" : "a demo for the csv_reader.js helper file.\nbang steps through the csv.\nclick open to see docs inside csv_reader.js" | |
} | |
} | |
, { | |
"box" : { | |
"id" : "obj-9", | |
"maxclass" : "newobj", | |
"numinlets" : 1, | |
"numoutlets" : 0, | |
"patching_rect" : [ 256.0, 230.0, 32.0, 22.0 ], | |
"text" : "print" | |
} | |
} | |
, { | |
"box" : { | |
"id" : "obj-6", | |
"maxclass" : "newobj", | |
"numinlets" : 1, | |
"numoutlets" : 1, | |
"outlettype" : [ "" ], | |
"patching_rect" : [ 102.0, 230.0, 71.0, 22.0 ], | |
"text" : "fromsymbol" | |
} | |
} | |
, { | |
"box" : { | |
"id" : "obj-4", | |
"maxclass" : "newobj", | |
"numinlets" : 1, | |
"numoutlets" : 0, | |
"patching_rect" : [ 102.0, 315.0, 32.0, 22.0 ], | |
"text" : "print" | |
} | |
} | |
, { | |
"box" : { | |
"id" : "obj-2", | |
"maxclass" : "newobj", | |
"numinlets" : 2, | |
"numoutlets" : 1, | |
"outlettype" : [ "int" ], | |
"patching_rect" : [ 102.0, 272.0, 32.0, 22.0 ], | |
"text" : "+ 10" | |
} | |
} | |
, { | |
"box" : { | |
"id" : "obj-7", | |
"maxclass" : "newobj", | |
"numinlets" : 1, | |
"numoutlets" : 0, | |
"patching_rect" : [ 188.0, 230.0, 32.0, 22.0 ], | |
"text" : "print" | |
} | |
} | |
, { | |
"box" : { | |
"id" : "obj-8", | |
"maxclass" : "message", | |
"numinlets" : 2, | |
"numoutlets" : 1, | |
"outlettype" : [ "" ], | |
"patching_rect" : [ 43.0, 95.0, 50.0, 22.0 ], | |
"text" : "compile" | |
} | |
} | |
, { | |
"box" : { | |
"id" : "obj-5", | |
"maxclass" : "button", | |
"numinlets" : 1, | |
"numoutlets" : 1, | |
"outlettype" : [ "bang" ], | |
"parameter_enable" : 0, | |
"patching_rect" : [ 155.0, 95.0, 24.0, 24.0 ] | |
} | |
} | |
, { | |
"box" : { | |
"id" : "obj-3", | |
"maxclass" : "message", | |
"numinlets" : 2, | |
"numoutlets" : 1, | |
"outlettype" : [ "" ], | |
"patching_rect" : [ 102.0, 95.0, 35.0, 22.0 ], | |
"text" : "open" | |
} | |
} | |
, { | |
"box" : { | |
"id" : "obj-1", | |
"maxclass" : "newobj", | |
"numinlets" : 1, | |
"numoutlets" : 2, | |
"outlettype" : [ "", "" ], | |
"patching_rect" : [ 102.0, 164.0, 135.0, 22.0 ], | |
"saved_object_attributes" : { | |
"filename" : "csv_reader.js", | |
"parameter_enable" : 0 | |
} | |
, | |
"text" : "js csv_reader.js test.csv" | |
} | |
} | |
], | |
"lines" : [ { | |
"patchline" : { | |
"destination" : [ "obj-6", 0 ], | |
"source" : [ "obj-1", 0 ] | |
} | |
} | |
, { | |
"patchline" : { | |
"destination" : [ "obj-7", 0 ], | |
"source" : [ "obj-1", 1 ] | |
} | |
} | |
, { | |
"patchline" : { | |
"destination" : [ "obj-4", 0 ], | |
"source" : [ "obj-2", 0 ] | |
} | |
} | |
, { | |
"patchline" : { | |
"destination" : [ "obj-1", 0 ], | |
"source" : [ "obj-3", 0 ] | |
} | |
} | |
, { | |
"patchline" : { | |
"destination" : [ "obj-1", 0 ], | |
"source" : [ "obj-5", 0 ] | |
} | |
} | |
, { | |
"patchline" : { | |
"destination" : [ "obj-2", 0 ], | |
"source" : [ "obj-6", 0 ] | |
} | |
} | |
, { | |
"patchline" : { | |
"destination" : [ "obj-1", 0 ], | |
"source" : [ "obj-8", 0 ] | |
} | |
} | |
], | |
"dependency_cache" : [ { | |
"name" : "csv_reader.js", | |
"bootpath" : "~/Documents", | |
"patcherrelativepath" : ".", | |
"type" : "TEXT", | |
"implicit" : 1 | |
} | |
], | |
"autosave" : 0 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
header1 | header2 | |
---|---|---|
1 | 2 | |
3 | 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
header1 | header2 | header3 | |
---|---|---|---|
1 | 2 | test | |
3 | 4 | test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment