Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cycle status monitor #1040

Open
jarmitage opened this issue Sep 19, 2023 · 0 comments
Open

Cycle status monitor #1040

jarmitage opened this issue Sep 19, 2023 · 0 comments
Labels
Feature Stream Issues related to the Stream functionality of playing Tidal patterns

Comments

@jarmitage
Copy link

I made this prototype via GPT (stopPrinting doesn't work!):

import Data.Fixed (mod')
import Text.Printf (printf)
import Control.Concurrent
import Control.Monad (forever, when)

streamGetnowMods :: Double -> Stream -> IO [Double]
streamGetnowMods mod s = do
  let mods = take 6 $ iterate (*2) mod
  result <- streamGetnow s
  return $! map (mod' result) mods

streamGetnowModsString :: Double -> Stream -> IO String
streamGetnowModsString mod s = do
  let mods = take 6 $ iterate (*2) mod
  results <- streamGetnowMods mod s
  cyclePos <- streamGetnow s
  let formattedResults = printf "%.0f: " cyclePos : zipWith (\x y -> printf "%d/%.0f" (floor x + 1) y) results mods
  return $ unwords formattedResults

printEverySecond :: Double -> Stream -> IO ()
printEverySecond mod s = forever $ do
    result <- streamGetnowModsString mod s
    cps <- streamGetcps s
    let delay = floor (1 / cps * 1000000) -- convert cps to microseconds
    putStrLn result
    threadDelay delay

startPrinting :: Double -> Stream -> IO (MVar ())
startPrinting mod s = do
    stopVar <- newEmptyMVar
    _ <- forkIO $ do
        let loop = do
                stopped <- tryTakeMVar stopVar
                Control.Monad.when (stopped == Nothing) $ do
                    printEverySecond mod s
                    loop
        loop
    return stopVar

stopPrinting :: MVar () -> IO ()
stopPrinting stopVar = do
    putMVar stopVar ()
    return ()

It prints out a status line like this:

706:  3/4 3/8 3/16 3/32 3/64 67/128
707:  4/4 4/8 4/16 4/32 4/64 68/128
708:  1/4 5/8 5/16 5/32 5/64 69/128
709:  2/4 6/8 6/16 6/32 6/64 70/128
710:  3/4 7/8 7/16 7/32 7/64 71/128
711:  4/4 8/8 8/16 8/32 8/64 72/128

I made this to help with composition and performance, makes it easier to keep track of things. Note that you don't have to use 4 as the base.

Would be cool to integrate this into an editor as feedback. I don't really know how to do that so just posting here for now!

@matthewkaney matthewkaney added Feature Stream Issues related to the Stream functionality of playing Tidal patterns labels Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Stream Issues related to the Stream functionality of playing Tidal patterns
Projects
None yet
Development

No branches or pull requests

2 participants