temporal-music-notation 0.1.3 → 0.1.4
raw patch · 3 files changed
+80/−29 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Temporal.Music.Notation.Pitch: scaleAt :: Scale -> Double -> Double
+ Temporal.Music.Notation.Pitch: scaleAtInt :: Scale -> Int -> Frequency
+ Temporal.Music.Notation.Pitch: scaleStep :: Scale -> Int -> Interval
+ Temporal.Music.Notation.Pitch: toneAsDouble :: Seg s => Tone s -> Double
+ Temporal.Music.Notation.Volume: diapasonAt :: Diapason -> Double -> Double
+ Temporal.Music.Notation.Volume: levelAsDouble :: Seg s => Level s -> Double
+ Temporal.Music.Notation.Volume: levelAsDoubleRel :: Seg s => Level s -> Double
+ Temporal.Music.Notation.Volume: setDiapasonRel :: VolumeFunctor a => (Double, Double) -> a -> a
+ Temporal.Music.Notation.Volume: unsafeLevelAsDouble :: Seg s => Level s -> Double
+ Temporal.Music.Notation.Volume: unsafeLevelAsDoubleRel :: Seg s => Level s -> Double
- Temporal.Music.Notation.Note: dqn :: (Pch nPch, Vol nVol) => Tone nPch -> Score (Note nVol nPch a)
+ Temporal.Music.Notation.Note: dqn :: (Vol nVol, Pch nPch) => Tone nPch -> Score (Note nVol nPch a)
- Temporal.Music.Notation.Note: qn :: (Pch nPch, Vol nVol) => Tone nPch -> Score (Note nVol nPch a)
+ Temporal.Music.Notation.Note: qn :: (Vol nVol, Pch nPch) => Tone nPch -> Score (Note nVol nPch a)
Files
- src/Temporal/Music/Notation/Pitch.hs +40/−16
- src/Temporal/Music/Notation/Volume.hs +38/−11
- temporal-music-notation.cabal +2/−2
src/Temporal/Music/Notation/Pitch.hs view
@@ -29,7 +29,8 @@ setBend, bend, step, transp, low, l', ll', high, h', hh', lower, higher, invert, -- * Rendering- frequency, absPitch+ frequency, absPitch,+ toneAsDouble, scaleAt, scaleAtInt, scaleStep ) where @@ -326,23 +327,46 @@ -- | calculates frequency value for given tone on scale grid frequency :: Seg n => Scale -> Tone n -> Frequency-frequency s t@(Tone b o n) = (bendCoeff r' d s * ) $- scaleFreq s d- where (b', r') = properFraction b- d = fromEnum t + fromIntegral b'+frequency s t = scaleAt s $ toneAsDouble t -bendCoeff :: Bend -> Step -> Scale -> Double-bendCoeff r n s- | abs r < 1e-6 = 1- | r > 0 = flip loginterpCoeff r $ getTones s n $ n + 1- | otherwise = flip loginterpCoeff (abs r) $ getTones s n $ n - 1- where getTones s n1 n2 = (scaleFreq s n1, scaleFreq s n2) - +-- | flattens tone to double.+toneAsDouble :: Seg s => Tone s -> Double+toneAsDouble t@(Tone b o s) = (fromIntegral $ fromEnum t) + b -scaleFreq :: Scale -> Int -> Frequency-scaleFreq s x = f0 * (scaleOctave s ^^ o) * (scaleSteps s V.! n)- where (o, n) = divMod (x - c0) $ scaleSize s- (c0, f0) = scaleBase s ++-- | scale value on doubles +scaleAt :: Scale -> Double -> Double+scaleAt s x = scaleAtInt s d * bendCoeff s n r + where (d, r) = properFraction x + n = mod (d - c0) $ scaleSize s+ c0 = fst $ scaleBase s++-- | scale value on integers +scaleAtInt :: Scale -> Int -> Frequency+scaleAtInt s x = f0 * scaleStep s x+ where f0 = snd $ scaleBase s ++-- | gives scale multiplier+scaleStep :: Scale -> Int -> Interval+scaleStep s x = (scaleOctave s ^ o) * scaleSteps s V.! n + where (o, n) = divMod (x - c0) $ scaleSize s+ c0 = fst $ scaleBase s+ ++bendCoeff :: Scale -> Int -> Double -> Frequency +bendCoeff s n x+ | abs x < 1e-6 = 1+ | x > 0 = flip loginterpCoeff x $ getTones s n $ n + 1+ | otherwise = flip loginterpCoeff (abs x) $ getTones s n $ n - 1+ where getTones s n1 n2 = (getTone s n1, getTone s n2) + getTone s x+ | x >= 0 && x < n = scaleSteps s V.! x+ | x == n = o+ | x == -1 = scaleSteps s V.! (n-1) / o+ | otherwise = error $ "scaleStep: out of bounds"+ where n = scaleSize s+ o = scaleOctave s+ loginterpCoeff :: (Double, Double) -> Double -> Double loginterpCoeff (l, r) x = (r / l) ** x
src/Temporal/Music/Notation/Volume.hs view
@@ -20,13 +20,16 @@ level, mediumLevel, -- * Transformers VolumeFunctor(..), LevelFunctor(..),- setDiapason, setLevel, setAccent,+ setDiapason, setDiapasonRel, setLevel, setAccent, accent, al', aq', loud, quiet, louder, quieter, dynamics, dynamicsRel, dynamicsSeg, -- * Rendering amplitude, unsafeAmplitude, - absVolume, unsafeAbsVolume+ absVolume, unsafeAbsVolume,+ diapasonAt, + levelAsDouble, unsafeLevelAsDouble,+ levelAsDoubleRel, unsafeLevelAsDoubleRel ) where @@ -68,9 +71,16 @@ instance Seg n => LevelFunctor (Volume n) where mapLevel f = \(Volume d l) -> Volume d $ f l --- | setDiapason+-- | sets diapason to specified value setDiapason :: VolumeFunctor a => (Amplitude, Amplitude) -> a -> a setDiapason x = mapVolume $ \(Volume _ l) -> Volume x l++-- | relative update of diapason value in decibels, +-- (0, 1) turns diapason interval into itself.+setDiapasonRel :: VolumeFunctor a => (Double, Double) -> a -> a+setDiapasonRel (a, b) = mapVolume $ + \(Volume x l) -> Volume (diapasonAt x a, diapasonAt x b) l+ -------------------------------------------------- -------------------------------------------------- -- Level@@ -225,20 +235,37 @@ -- Here resulting amplitude value lies within 'Diapason' interval. -- All outsiders are placed inside interval with saturation. amplitude :: Seg n => Diapason -> Level n -> Amplitude-amplitude d l = amplitudeGen (sat 0 $ fromIntegral $ levelNum l) d l+amplitude d l = diapasonAt d $ levelAsDoubleRel l -- | unsafe analog of 'amplitude' function. Here result can go -- beyond limits of 'Diapason' interval. unsafeAmplitude :: Seg n => Diapason -> Level n -> Amplitude-unsafeAmplitude = amplitudeGen id+unsafeAmplitude d l = diapasonAt d $ unsafeLevelAsDouble l -amplitudeGen :: Seg n - => (Double -> Double)- -> Diapason -> Level n -> Amplitude-amplitudeGen bound (low, high) l@(Level a s) = (low * ) $ (high / low) ** x- where n = fromIntegral $ levelNum l- x = ( / n) $ bound $ (fromIntegral $ fromEnum s) + a+-- | mapps decibels to amplitudes within specified amplitude diapason,+-- 0 turns to lower diapason value and 1 turns to higher diapason value+diapasonAt :: Diapason -> Double -> Double+diapasonAt (low, high) d = (low * ) $ (high / low) ** d +-- | converts level value to double+levelAsDouble :: Seg s => Level s -> Double+levelAsDouble x = sat 0 n $ unsafeLevelAsDouble x+ where n = fromIntegral $ levelNum x - 1++-- | converts level value to double, value can exceed level limits+unsafeLevelAsDouble :: Seg s => Level s -> Double+unsafeLevelAsDouble l@(Level a x) = (fromIntegral $ fromEnum l) + a++-- | converts level value to double, and normalizes output by level limits+levelAsDoubleRel :: Seg s => Level s -> Double+levelAsDoubleRel l = (/n) $ levelAsDouble l+ where n = fromIntegral $ levelNum l - 1++-- | converts level value to double and normalizes output by level limits, +-- value can exceed (0, 1) interval+unsafeLevelAsDoubleRel :: Seg s => Level s -> Double+unsafeLevelAsDoubleRel l = (/n) $ unsafeLevelAsDoubleRel l+ where n = fromIntegral $ levelNum l - 1 -------------------------------------- -- level manipulation
temporal-music-notation.cabal view
@@ -1,10 +1,10 @@ Name: temporal-music-notation-Version: 0.1.3+Version: 0.1.4 Cabal-Version: >= 1.2 License-file: LICENSE License: BSD3 Author: Anton Kholomiov-Maintainer: Anton Kholomiov+Maintainer: <anton.kholomiov@gmail.com> Synopsis: music notation Description: Library for expressing musical ideas. Includes composable score representation, microsound tunings, flexible pitch and volume control. Category: Music