This commit is contained in:
2024-03-25 20:08:53 +01:00
parent c9592fadd2
commit 455aa7fc31
19 changed files with 141 additions and 25 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,86 +0,0 @@
:set -XOverloadedStrings
:set prompt ""
:cd /home/phillip/Projekte/HTWK/Computermusik/data-composition/scratchpads
import Sound.Tidal.Context
import System.IO (hSetEncoding, stdout, utf8)
hSetEncoding stdout utf8
-- Load Data
:l TemperatureData HumidityData BatteryData
tidal <- startTidal (superdirtTarget {oLatency = 0.05, oAddress = "127.0.0.1", oPort = 57120}) (defaultConfig {cVerbose = True, cFrameTimespan = 1/20})
:{
let only = (hush >>)
p = streamReplace tidal
hush = streamHush tidal
panic = do hush
once $ sound "superpanic"
list = streamList tidal
mute = streamMute tidal
unmute = streamUnmute tidal
unmuteAll = streamUnmuteAll tidal
unsoloAll = streamUnsoloAll tidal
solo = streamSolo tidal
unsolo = streamUnsolo tidal
once = streamOnce tidal
first = streamFirst tidal
asap = once
nudgeAll = streamNudgeAll tidal
all = streamAll tidal
resetCycles = streamResetCycles tidal
setCycle = streamSetCycle tidal
setcps = asap . cps
getcps = streamGetcps tidal
getnow = streamGetnow tidal
xfade i = transition tidal True (Sound.Tidal.Transition.xfadeIn 4) i
xfadeIn i t = transition tidal True (Sound.Tidal.Transition.xfadeIn t) i
histpan i t = transition tidal True (Sound.Tidal.Transition.histpan t) i
wait i t = transition tidal True (Sound.Tidal.Transition.wait t) i
waitT i f t = transition tidal True (Sound.Tidal.Transition.waitT f t) i
jump i = transition tidal True (Sound.Tidal.Transition.jump) i
jumpIn i t = transition tidal True (Sound.Tidal.Transition.jumpIn t) i
jumpIn' i t = transition tidal True (Sound.Tidal.Transition.jumpIn' t) i
jumpMod i t = transition tidal True (Sound.Tidal.Transition.jumpMod t) i
jumpMod' i t p = transition tidal True (Sound.Tidal.Transition.jumpMod' t p) i
mortal i lifespan release = transition tidal True (Sound.Tidal.Transition.mortal lifespan release) i
interpolate i = transition tidal True (Sound.Tidal.Transition.interpolate) i
interpolateIn i t = transition tidal True (Sound.Tidal.Transition.interpolateIn t) i
clutch i = transition tidal True (Sound.Tidal.Transition.clutch) i
clutchIn i t = transition tidal True (Sound.Tidal.Transition.clutchIn t) i
anticipate i = transition tidal True (Sound.Tidal.Transition.anticipate) i
anticipateIn i t = transition tidal True (Sound.Tidal.Transition.anticipateIn t) i
forId i t = transition tidal False (Sound.Tidal.Transition.mortalOverlay t) i
d1 = p 1 . (|< orbit 0)
d2 = p 2 . (|< orbit 1)
d3 = p 3 . (|< orbit 2)
d4 = p 4 . (|< orbit 3)
d5 = p 5 . (|< orbit 4)
d6 = p 6 . (|< orbit 5)
d7 = p 7 . (|< orbit 6)
d8 = p 8 . (|< orbit 7)
d9 = p 9 . (|< orbit 8)
d10 = p 10 . (|< orbit 9)
d11 = p 11 . (|< orbit 10)
d12 = p 12 . (|< orbit 11)
d13 = p 13
d14 = p 14
d15 = p 15
d16 = p 16
:}
:{
let getState = streamGet tidal
setI = streamSetI tidal
setF = streamSetF tidal
setS = streamSetS tidal
setR = streamSetR tidal
setB = streamSetB tidal
:}
:set prompt "tidal> "
:set prompt-cont ""
default (Pattern String, Integer, Double)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,17 +1,16 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
-- This requires my custom BootTidal.hs
import Prelude hiding (filter)
import qualified Data.ByteString.Lazy as BL
import Data.Csv -- this is from the Cassava library
import qualified Data.Vector as V
-- import System.Directory (doesFileExist)
-- import Text.Printf
-- import Control.Monad (forM_)
import GHC.IO.Exception
import Data.List
import Control.Exception (try)
import qualified Data.ByteString.Lazy as BL
import qualified Data.Vector as V
import Graphics.Matplotlib
data TimestampedDatum = TimestampedDatum {
timestamp :: String,
@@ -30,6 +29,8 @@ instance FromNamedRecord TimestampedDatum where
type ErrorMsg = String
type CsvData = (Header, V.Vector TimestampedDatum)
data CsvData = CsvData (Header, V.Vector TimestampedDatum)
parseCsv :: FilePath -> IO (Either ErrorMsg CsvData)
parseCsv filePath = do
result <- try $ BL.readFile filePath
@@ -37,8 +38,16 @@ parseCsv filePath = do
Left (exception :: IOException) -> Left $ show exception
Right contents -> decodeByName contents
getList :: CsvData -> V.Vector TimestampedDatum
getList = snd
getList :: Either ErrorMsg CsvData -> [Float]
getList maybeCsvData = case maybeCsvData of
CsvData (_, v) -> map datum v
ErrorMsg _ -> []
getList parseCsv dataPath
d1 =<< (fmap (\x -> ) (parseCsv dataPath))
-- getValue :: TimestampedDatum -> Float
-- getValue = datum
onscreen $ getList parseCsv dataPath

View File

@@ -2,4 +2,6 @@
d7 $ s "superpiano*2" # n (quantise 1 (perlin * 10))
-- Why does the following not work then???
d7 $ s "superpiano*2" # n (scale "major" (perlin * 10))
d3 $ s "superpiano*2" # scale "major" n (quantise 1 ((perlin * 10)))
d1 $ s "bd"

View File

@@ -1,5 +1,3 @@
import TemperatureData
data ValueRecord a = ValueRecord {
time :: Data.Time.UTCTime,
value :: a

View File

@@ -4,10 +4,43 @@ import Sound.Tidal.Chords
import TemperatureData
import HumidityData
import BatteryData
import Graphics.Gnuplot.Simple
import qualified Graphics.Gnuplot.Terminal.QT as QT
import System.Random
d1 $ s "bd"
d1 $ s "[bd*4, ~!2 hh ~ hh*3 hh ~]" # room 0.1
randInt :: Int -> Int -> IO Int
randInt minVal maxVal = randomRIO (minVal, maxVal)
getRawValueList :: [(a, a)] -> [a]
getRawValueList tableData = map (\x -> snd x) tableData
getRawLabelList :: [(b, b)] -> [b]
getRawLabelList tableData = map (\x -> fst x) tableData
makePlottableList :: [c] -> [(Int, c)]
makePlottableList list = zip [0..] list
plotPlainList :: [(Int, d)] -> IO ()
plotPlainList list = plotList [] $ makePlottableList list
listToNum :: [String] -> [Float]
listToNum list = map (\x -> getNum x 1) list
getRandomStartIndex :: Int -> Int -> IO Int
getRandomStartIndex listLength sliceSize = do
gen <- getStdGen
let validRange = listLength - sliceSize + 1
randomInt <- randomR (0, validRange - 1) gen
return randomInt
randomSlice :: Int -> [a] -> [a]
randomSlice list length = take
getNum :: String -> Float -> Float
getNum value scalar = fromInteger $ round $ (maybe 0.0 id (readMaybe value :: Maybe Float)) * scalar
sliceList start end list = take (end - start + 1) (drop start list)
@@ -17,15 +50,34 @@ let temperatureScalar = 10
temperature = fast 4 $ n ("x(3,5)" |> temperaturePattern + "['maj | 'min]" )# s "superpiano" # room 0.5
in d1 $ temperature
queryArc (n ("1 2 3 4 5 6 7 8")) (Arc 0 1)
:i fromInteger
getRawLabelList temper
:t temperaturedata
length $ listToNum $ getRawValueList $ temperaturedata
plotList [] (zip [0..] (listToNum (getRawValueList $ take 10 temperaturedata)))
:t temperaturedata
selection = listToNum (getRawValueList $ take 10 temperaturedata)
plotPlainList (selection)
let batteryScalar = 5
batteryPattern = scale "major" (fromList (map (\x -> getNum x batteryScalar) (map (\x -> snd x) (sliceList 500 510 batterydata))) |- 150)
battery = n ("x(3,5)" |> batteryPattern + "['maj | 'min]" )# s "jvbass" # room 0.5
in d2 $ battery
batteryScalar = 5
batteryPattern = scale "major" (fromList (map (\x -> getNum x batteryScalar) (map (\x -> snd x) (sliceList 500 510 batterydata))) |- 150)
battery = n ("x(3,5)" |> batteryPattern + "['maj | 'min]" )
batteryScalar = 5
queryArc battery (Arc 0 2)
queryArc temperature (Arc 0 2.5)
@@ -39,9 +91,5 @@ d1 $ trigger $ s "<bd sn*4 bd sn*2>"
d1 $ n ( run 10) # s "v"
:t map (\x -> getMaybeFloat (snd x)) (take 100 temperaturedata)
queryArc (n("c'maj f4'maj'ii g4'maj'i c'maj")) (Arc 0 1)
d1 $ n("c'maj f4'maj'ii g4'maj'i c'maj") # s "superpiano"
scaleTable
chordTable