Ask Your Question
0

It is possible to import json or csv files?

asked 2017-02-09 15:13:41 -0500

bram gravatar image

updated 2017-02-09 15:15:30 -0500

Hello all! TidalCycles is great stuff. I want to make music with (real time) data, so is it possible to import json or csv files into TidalCycles? Would be nice.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-02-09 16:54:47 -0500

bgold gravatar image

Haskell can do it, but you might need to install some modules.

I managed to get something going by first installing the csv package from the command line

cabal install csv

Then from your Tidal session (or any interactive Haskell prompt) you can do something like

import Text.CSV
import Data.Either
result <- parseCSVFromFile "path/yourfile.csv"
let rec = (rights [result])!!0

From then on you can treat rec kind of like a 2D array and index it with multiple !! operators. So if the csv file looked like this:

"foo", 1
"bear", 2

Then rec!!0!!1 would return " 1". It keeps it as a string-like object and even keeps the space. If you want to convert it, you can use the read function with an explicit cast

let f = (read $ rec!!0!!1)::Float

So f is now a floating point value 1.0

I'm not very familiar with all this so there are probably other modules (that might need installing) to make working with the structure a bit easier. In particular, if you want to pull out a data column you can define a function to get a specific entry and then map it over the rows, but there must be a nice wrapper for that somewhere.

edit flag offensive delete link more

Comments

thanks so much bgold!

bram gravatar imagebram ( 2017-02-11 08:22:24 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-02-09 15:13:41 -0500

Seen: 53 times

Last updated: Feb 09