temporal-music-notation-demo 0.1.4 → 0.1.5
raw patch · 2 files changed
+50/−31 lines, 2 filesdep −cmathdep ~temporal-music-notationPVP ok
version bump matches the API change (PVP)
Dependencies removed: cmath
Dependency ranges changed: temporal-music-notation
API changes (from Hackage documentation)
Files
src/Temporal/Music/Notation/Demo.hs view
@@ -21,20 +21,12 @@ import Data.Binary import Data.Binary.Put -import Foreign.C.Math.Double(log10) import Codec.Midi hiding (Time) import Temporal.Music.Notation import Temporal.Music.Notation.Note --- cmath--log2 :: Double -> Double-log2 x = log10 x / log10 2--logB :: Double -> Double -> Double-logB b x = log10 x / log10 b-+log2 = logBase 2 ----------------------------------------------------------------- -- Types@@ -190,14 +182,6 @@ where t = fst --{--toMessages :: Channel -> LowMidiEvent -> (Message, Message) -toMessages ch x = (NoteOn ch key vel, NoteOff ch key 64)- where key = fst $ lmeventPch x- vel = lmeventVol x --}- toMessages :: Channel -> LowMidiEvent -> ([Message], Message) toMessages ch x = toMessages' ch vel key tune where key = fst $ lmeventPch x@@ -218,19 +202,55 @@ lowLevel :: Diapason -> MidiEvent -> LowMidiEvent lowLevel diap (MidiEvent i v p) = LowMidiEvent vol pch- where vol = fitToMidiDiapason diap $ absVolume v- pch = maybe (i, 0) (midiPch . absPitch) p+ where vol = midiVol diap v+ pch = maybe (i, 0) midiPch p -fitToMidiDiapason :: Diapason -> Amplitude -> VolumeId-fitToMidiDiapason (a, b) x = round $ 127 * logB (b/a) (x/a) - {- logBase (b/a) (x/a) -}+clipToMidi :: (Num a, Ord a) => a -> a+clipToMidi = min 127 . max 0 -midiPch :: Frequency -> PitchId-midiPch x = properFraction $ bound $ 69 + 12 * log2 (x/440) - {- logBase 2 (x / 440) -}- where bound = max 0 . min 127 +-------------------+-- midi volume +midiVol (a', b') (Volume (a, b) l) = + clipToMidi $ round $ (127 * ) $ + x * logBase (b'/a') (b/a) + logBase (b'/a') (a/a')+ where x = levelAsDoubleRel l+ +--------------------+-- midi pitch +midiPch :: Seg s => Pitch s -> PitchId+midiPch (Pitch s t) = properFraction $ clipToMidi $ + 69 + 12 * (scaleStepFactor s n + + scaleOctaveFactor s k + scaleBendFactor s n r)+ where (d, r) = properFraction $ toneAsDouble t+ (k, n) = divMod d $ scaleSize s+ +-- log2 (f0 * s / 440)+scaleStepFactor :: Scale -> Int -> Double+scaleStepFactor s n = log2 $ scaleStep s n * f0 / 440+ where f0 = snd $ scaleBase s++-- k * log2 d+scaleOctaveFactor :: Scale -> Int -> Double+scaleOctaveFactor s k + | abs (d - 2) < 1e-9 = k'+ | otherwise = k' * log2 d+ where d = scaleOctave s+ k' = fromIntegral k ++-- x * log2 (r/l)+scaleBendFactor :: Scale -> Int -> Double -> Double+scaleBendFactor s n x + | abs x < 1e-9 = 0+ | x > 0 = x * log2 (r / c)+ | otherwise = abs x * log2 (l / c)+ where c = scaleStep s n+ l = scaleStep s $ n - 1+ r = scaleStep s $ n + 1++ +------------------------- toTicks :: Time -> Ticks toTicks = round . ( * division2)
temporal-music-notation-demo.cabal view
@@ -1,10 +1,10 @@ Name: temporal-music-notation-demo-Version: 0.1.4+Version: 0.1.5 Cabal-Version: >= 1.2 License: BSD3 License-file: LICENSE Author: Anton Kholomiov-Maintainer: Anton Kholomiov+Maintainer: <anton.kholomiov@gmail.com> Synopsis: generates midi from score notation. Description: Library for playing scores made with 'temporal-music-notation' via midi. It binds 'temporal-media-notation' and 'HCodecs' @@ -28,9 +28,8 @@ Library Build-Depends: base >= 4, base < 5,- temporal-music-notation >= 0.1.3,- HCodecs >= 0.2, binary >= 0.5.0.2,- cmath >= 0.3+ temporal-music-notation >= 0.1.4,+ HCodecs >= 0.2, binary >= 0.5.0.2 Hs-Source-Dirs: src/ Exposed-Modules: Temporal.Music.Notation.Demo