packages feed

synthesizer-llvm-0.9: alsa/Synthesizer/LLVM/Server/Scalar/Test.hs

module Synthesizer.LLVM.Server.Scalar.Test where

import qualified Synthesizer.LLVM.Server.Scalar.Instrument as Instr
import qualified Synthesizer.LLVM.Server.Option as Option
import qualified Synthesizer.LLVM.Server.Default as Default
import Synthesizer.LLVM.Server.Scalar.Run (withMIDIEvents)
import Synthesizer.LLVM.Server.ALSA (record, put, makeNote)
import Synthesizer.LLVM.Server.Common

import qualified Synthesizer.ALSA.Storable.Play as Play
import qualified Sound.ALSA.Sequencer.Event as Event

import qualified Synthesizer.MIDI.PiecewiseConstant as PC
import qualified Synthesizer.MIDI.Generic as Gen

import qualified Synthesizer.LLVM.CausalParameterized.Process as CausalP
import qualified Synthesizer.LLVM.Parameterized.Signal as SigP
import qualified Synthesizer.LLVM.Wave as WaveL
import Synthesizer.LLVM.Causal.Process (($<#), ($*))

import qualified Synthesizer.Storable.Cut         as CutSt
import qualified Synthesizer.Storable.Signal      as SigSt
import qualified Data.StorableVector.Lazy         as SVL

import qualified Data.EventList.Relative.TimeBody  as EventList

import Control.Arrow (arr)
import Control.Monad.Trans.State (evalState)

import NumericPrelude.Numeric (zero)
import Prelude hiding (Real)


chunkSize :: SVL.ChunkSize
chunkSize = Play.defaultChunkSize

sampleRatePlain :: Real
sampleRatePlain = case Default.sampleRate of SampleRate r -> r

sampleRate :: SampleRate Real
sampleRate = Default.sampleRate


pitchBend0 :: IO ()
pitchBend0 = do
   osc <-
      SigP.runChunky
         ((CausalP.osciSimple WaveL.triangle $<# (zero::Real))
             $* piecewiseConstant (arr id))
   SVL.writeFile "test.f32" $
      (id :: SigSt.T Real -> SigSt.T Real) .
      osc chunkSize .
      evalState (PC.pitchBend Default.channel 2 (880/sampleRatePlain)) $
      let evs = EventList.cons 100 [] evs
      in  EventList.cons 0 ([]::[Event.T]) evs

pitchBend1 :: IO ()
pitchBend1 = do
   opt <- Option.get
   osc <-
      SigP.runChunky
         ((CausalP.osciSimple WaveL.triangle $<# (zero::Real))
             $* piecewiseConstant (arr id))
   withMIDIEvents opt (record "test.f32") $ \ _size _rate ->
      (id :: SigSt.T Real -> SigSt.T Real) .
      osc chunkSize .
      evalState (PC.pitchBend Default.channel 2 (880/sampleRatePlain))

pitchBend2 :: IO ()
pitchBend2 = do
   opt <- Option.get
   withMIDIEvents opt put $ \ _size _rate -> id



sequencePress :: IO ()
sequencePress = do
--   arrange <- SigStL.makeArranger
--   sound <- Instr.softString
--   sound <- Instr.softStringReleaseEnvelope
--   sound <- Instr.pingReleaseEnvelope $/ 1 $/ chunkSize
--   sound <- Instr.pingDur
--   sound <- Instr.pingDurTake
   let sound = Instr.dummy chunkSize Default.sampleRate
   SVL.writeFile "test.f32" $
      CutSt.arrange chunkSize $
      evalState
         (do Gen.sequence Default.channel sound) $
      let evs t =
             EventList.cons t [makeNote Event.NoteOn  60] $
             EventList.cons t [makeNote Event.NoteOff 60] $
             evs (20-t)
      in  evs 10