diff --git a/.gitmodules b/.gitmodules index 5cac3e5..4df42cb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "paper"] path = paper url = https://git@git.overleaf.com/65c0de00fe99eea78a9ac0df +[submodule "tools/Troop"] + path = tools/Troop + url = https://github.com/Qirky/Troop.git diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b9f02a0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,22 @@ +{ + "workbench.colorCustomizations": { + "activityBar.activeBackground": "#43920a", + "activityBar.background": "#43920a", + "activityBar.foreground": "#e7e7e7", + "activityBar.inactiveForeground": "#e7e7e799", + "activityBarBadge.background": "#a6c8f9", + "activityBarBadge.foreground": "#15202b", + "commandCenter.border": "#e7e7e799", + "sash.hoverBorder": "#43920a", + "statusBar.background": "#2d6207", + "statusBar.foreground": "#e7e7e7", + "statusBarItem.hoverBackground": "#43920a", + "statusBarItem.remoteBackground": "#2d6207", + "statusBarItem.remoteForeground": "#e7e7e7", + "titleBar.activeBackground": "#2d6207", + "titleBar.activeForeground": "#e7e7e7", + "titleBar.inactiveBackground": "#2d620799", + "titleBar.inactiveForeground": "#e7e7e799" + }, + "peacock.color": "#2d6207" +} \ No newline at end of file diff --git a/BootTidal.hs b/BootTidal.hs deleted file mode 120000 index 4e4078d..0000000 --- a/BootTidal.hs +++ /dev/null @@ -1 +0,0 @@ -scratchpads/BootTidal.hs \ No newline at end of file diff --git a/data/weather/balcony_temperature.csv b/data/weather/balcony_temperature.csv index 1d51f5b..0c3ebeb 100644 --- a/data/weather/balcony_temperature.csv +++ b/data/weather/balcony_temperature.csv @@ -1,4 +1,4 @@ -"time","°C.value" +"time","C.value" "2023-01-01T00:00:04.009+01:00","15.2" "2023-01-01T00:09:40.198+01:00","15" "2023-01-01T00:58:31.315+01:00","14.9" diff --git a/scratchpads/BatteryData.hs b/datamodules/BatteryData.hs similarity index 100% rename from scratchpads/BatteryData.hs rename to datamodules/BatteryData.hs diff --git a/scratchpads/HumidityData.hs b/datamodules/HumidityData.hs similarity index 100% rename from scratchpads/HumidityData.hs rename to datamodules/HumidityData.hs diff --git a/scratchpads/TemperatureData.hs b/datamodules/TemperatureData.hs similarity index 100% rename from scratchpads/TemperatureData.hs rename to datamodules/TemperatureData.hs diff --git a/paper b/paper index f69ec93..53166e0 160000 --- a/paper +++ b/paper @@ -1 +1 @@ -Subproject commit f69ec93db93c2277168a64e0ecebfa22880cb6ee +Subproject commit 53166e07376e51d9f93c2d7c0d6f6c546bcdea88 diff --git a/scratchpads/csv.hs b/scratchpads/csv.tidal similarity index 73% rename from scratchpads/csv.hs rename to scratchpads/csv.tidal index 4c10f32..dda89a6 100644 --- a/scratchpads/csv.hs +++ b/scratchpads/csv.tidal @@ -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 \ No newline at end of file diff --git a/scratchpads/data_to_melody.tidal b/scratchpads/data_to_melody.tidal index df0f041..579da13 100644 --- a/scratchpads/data_to_melody.tidal +++ b/scratchpads/data_to_melody.tidal @@ -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)) \ No newline at end of file +d3 $ s "superpiano*2" # scale "major" n (quantise 1 ((perlin * 10))) + +d1 $ s "bd" \ No newline at end of file diff --git a/scratchpads/hs_wrapped_data.hs b/scratchpads/hs_wrapped_data.hs index 504e3aa..a29990c 100644 --- a/scratchpads/hs_wrapped_data.hs +++ b/scratchpads/hs_wrapped_data.hs @@ -1,5 +1,3 @@ -import TemperatureData - data ValueRecord a = ValueRecord { time :: Data.Time.UTCTime, value :: a diff --git a/scratchpads/lists.tidal b/scratchpads/lists.tidal index 67d4af2..bfd6107 100644 --- a/scratchpads/lists.tidal +++ b/scratchpads/lists.tidal @@ -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 "" 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 \ No newline at end of file diff --git a/tools/.python-version b/tools/.python-version new file mode 100644 index 0000000..c8cfe39 --- /dev/null +++ b/tools/.python-version @@ -0,0 +1 @@ +3.10 diff --git a/scratchpads/BootTidal.hs b/tools/BootTidal.hs similarity index 92% rename from scratchpads/BootTidal.hs rename to tools/BootTidal.hs index c593985..22489b6 100644 --- a/scratchpads/BootTidal.hs +++ b/tools/BootTidal.hs @@ -1,12 +1,20 @@ :set -XOverloadedStrings +:set -XExtendedDefaultRules :set prompt "" -:cd /home/phillip/Projekte/HTWK/Computermusik/data-composition/scratchpads + +-- Load Data. This currently is pinned to my setup. +:cd /home/phillip/Projekte/HTWK/Computermusik/data-composition/datamodules import Sound.Tidal.Context import System.IO (hSetEncoding, stdout, utf8) hSetEncoding stdout utf8 +-- Expose otherwise hidden modules +:set -package vector +:set -package bytestring +:set -package random + -- Load Data :l TemperatureData HumidityData BatteryData diff --git a/tools/Troop b/tools/Troop new file mode 160000 index 0000000..529c5eb --- /dev/null +++ b/tools/Troop @@ -0,0 +1 @@ +Subproject commit 529c5eb14e456f683e6d23fd4adcddc8446aa115 diff --git a/tools/superdirt.sh b/tools/superdirt.sh index 121a5dd..58d5586 100755 --- a/tools/superdirt.sh +++ b/tools/superdirt.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Make SuperCollider construct the Path to the default SuperDirt startup file and load it. # Afterwards direct stdin to sclang so we can control it. (echo -e 'load(Platform.userAppSupportDir+/+"/downloaded-quarks/SuperDirt/superdirt_startup.scd")' && cat) | sclang \ No newline at end of file diff --git a/tools/troop_client_no_interpreter.sh b/tools/troop_client_no_interpreter.sh new file mode 100755 index 0000000..660b9c4 --- /dev/null +++ b/tools/troop_client_no_interpreter.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# Script location +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "$SCRIPT") + +cd "$SCRIPTPATH"/Troop || exit +# Explicit python version is on purpose, Troop won't work with python 3.11+ +python3.10 run-client.py --syntax "tidalcycles" --mode "none" \ No newline at end of file diff --git a/tools/troop_client_with_tidal_interpreter.sh b/tools/troop_client_with_tidal_interpreter.sh new file mode 100755 index 0000000..813dd4c --- /dev/null +++ b/tools/troop_client_with_tidal_interpreter.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# Script location +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "$SCRIPT") + +cd "$SCRIPTPATH"/Troop || exit +# Explicit python version is on purpose, Troop won't work with python 3.11+ +python3.10 run-client.py --cli --syntax "tidalcycles" --mode $(which ghci) --args "-ghci-script $SCRIPTPATH/BootTidal.hs" \ No newline at end of file diff --git a/tools/troop_server.sh b/tools/troop_server.sh new file mode 100755 index 0000000..255528c --- /dev/null +++ b/tools/troop_server.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# Script location +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "$SCRIPT") +PROJECTBASEDIR=$(dirname "$SCRIPTPATH") + +cd "$SCRIPTPATH"/Troop || exit +# Explicit python version is on purpose, Troop won't work with python 3.11+ +python3.10 run-server.py \ No newline at end of file