packages feed

dobutokO2 0.24.6.0 → 0.25.0.0

raw patch · 3 files changed

+79/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ DobutokO.Sound.Functional: fAddFElem :: (Double, Double) -> Double -> (Double -> OvertonesO) -> ((Double, Double) -> Double -> (Double -> OvertonesO) -> OvertonesO) -> Double -> OvertonesO
+ DobutokO.Sound.Functional: fRemoveFElem :: (Double, Double) -> Double -> (Double -> OvertonesO) -> ((Double, Double) -> Double -> (Double -> OvertonesO) -> OvertonesO) -> Double -> OvertonesO
+ DobutokO.Sound.Functional: gAdd01 :: (Double, Double) -> Double -> (Double -> OvertonesO) -> OvertonesO
+ DobutokO.Sound.Functional: renormF :: OvertonesO -> OvertonesO
+ DobutokO.Sound.Functional: renormFD :: Double -> OvertonesO -> OvertonesO
+ DobutokO.Sound.Functional: sameFreqF :: Double -> (Double, Double) -> (Double -> OvertonesO) -> ((Double, Double) -> OvertonesO -> OvertonesO) -> OvertonesO
+ DobutokO.Sound.Functional: sameFreqFI :: Double -> (Double, Double) -> (Double -> OvertonesO) -> ((Double, Double) -> OvertonesO -> OvertonesO) -> OvertonesO
+ DobutokO.Sound.Functional: sameOvertone :: OvertonesO -> Bool
+ DobutokO.Sound.Functional: sameOvertoneL :: [(Double, Double)] -> Bool

Files

CHANGELOG.md view
@@ -246,3 +246,7 @@ ## 0.24.6.0 -- 2020-04-07  * Twenty-fourth version revised F. Fixed issue with being not compiled.++## 0.25.0.0 -- 2020-04-09++* Twenty-fifth version. Added more possibilities to edit function f from the DobutokO.Sound.Functional module. 
DobutokO/Sound/Functional.hs view
@@ -100,6 +100,16 @@   , maybeFFromStrVec   , fVecCoefs   , showFFromStrVec+  -- * Functions to edit 'OvertonesO' and function f (since 0.25.0.0)+  , renormF+  , renormFD+  , sameOvertone+  , sameOvertoneL  +  , sameFreqF+  , sameFreqFI+  , fAddFElem+  , fRemoveFElem+  , gAdd01 ) where  import Text.Read (readMaybe)@@ -984,3 +994,67 @@         l = length ("(" ++ (showFFloat Nothing y "") ++ ",(\t -> <(" ++ concat (V.toList . V.map (\z -> (showFFloat Nothing (fst z) $               " * t, " ++ (showFFloat Nothing (snd z) $ "),("))) $ (f 1))) in take (l - 2) ("(" ++ (showFFloat Nothing y "") ++ ",(\t -> <("                 ++ concat (V.toList . V.map (\z -> (showFFloat Nothing (fst z) $ " * t, " ++ (showFFloat Nothing (snd z) $ "),("))) $ (f 1))) ++ ">))"++----------------------------------------------------------------------------------------++-- | Renormalizes amplitudes for the frequencies so that the maximum one of them (if 'OvertonesO' is not 'V.empty') is equal by the absolute value+-- to 1.0 and the mutual ratios of the amplitudes are preserved.+renormF :: OvertonesO -> OvertonesO+renormF v+ | V.null v = V.empty+ | otherwise =+    let v1 = V.fromList . sortBy (\(x1,y1) (x2,y2)-> compare (abs y2) (abs y1)) . V.toList $ v in+      V.map (\(x,y) -> (x, y / (snd . V.unsafeIndex v1 $ 0))) v1++-- | Renormalizes amplitudes for the frequencies so that the maximum one of them (if 'OvertonesO' is not 'V.empty') is equal by the absolute value+-- to 'Double' argument and the mutual ratios of the amplitudes are preserved.+renormFD :: Double -> OvertonesO -> OvertonesO+renormFD ampl0 v+ | V.null v = V.empty+ | otherwise =+    let v1 = V.fromList . sortBy (\(x1,y1) (x2,y2)-> compare (abs y2) (abs y1)) . V.toList $ v in+      V.map (\(x,y) -> (x, ampl0 * y / (snd . V.unsafeIndex v1 $ 0))) v1      ++-- | Predicate to check whether all tuples in a 'V.Vector' have the same first element.+sameOvertone :: OvertonesO -> Bool+sameOvertone v+ | V.null v = False+ | otherwise = V.all (\(x,_) -> x == (fst . V.unsafeIndex v $ 0)) v++-- | Similar to 'sameOvertone', except that not the 'V.Vector' is checked but a corresponding list.+sameOvertoneL :: [(Double,Double)] -> Bool+sameOvertoneL xs@((x,y):_) = all (\(xn,_) -> xn == x) xs+sameOvertoneL _ = False++-- | @g :: (Double,Double) -> OvertonesO -> OvertonesO@ is a function that defines how the new element is added to the 'OvertonesO'.+sameFreqF :: Double -> (Double,Double) -> (Double -> OvertonesO) -> ((Double,Double) -> OvertonesO -> OvertonesO) -> OvertonesO+sameFreqF freq (noteN0,amplN0) f g = g (noteN0,amplN0) (f freq)++-- | @g :: (Double,Double) -> OvertonesO -> OvertonesO@ is a function that defines how the new element is added to the 'OvertonesO'.+-- Variant of 'sameFreqF' where g depends only on the elements of the 'OvertonesO', which first elements in the tuples equal to the first element+-- in the @(Double,Double)@.+sameFreqFI :: Double -> (Double,Double) -> (Double -> OvertonesO) -> ((Double,Double) -> OvertonesO -> OvertonesO) -> OvertonesO+sameFreqFI freq (noteN0,amplN0) f g = g (noteN0,amplN0) . V.filter (\(x,y) -> x == noteN0) $ f freq++-- | @gAdd :: (Double,Double) -> Double -> (Double -> OvertonesO) -> OvertonesO@ is a function that defines how the element is added+-- to the 'OvertonesO'.+fAddFElem :: (Double, Double) -> Double -> (Double -> OvertonesO) -> ((Double,Double) -> Double -> (Double -> OvertonesO) -> OvertonesO) ->+  (Double -> OvertonesO)+fAddFElem (noteN,amplN) freq f gAdd = \t -> gAdd (noteN,amplN) t f++-- | @gRem:: (Double,Double) -> Double -> (Double -> OvertonesO) -> OvertonesO@ is a function that defines how the element is removed+-- from the 'OvertonesO'.+fRemoveFElem :: (Double, Double) -> Double -> (Double -> OvertonesO) -> ((Double,Double) -> Double -> (Double -> OvertonesO) -> OvertonesO) ->+  (Double -> OvertonesO)+fRemoveFElem (noteN,amplN) freq f gRem = \t -> gRem (noteN,amplN) t f++-- | Example of the function gAdd for the 'fAddFElem'. If the frequency is already in the 'OvertonesO' then the corresponding amplitude is divided+-- equally between all the elements with the repeated given frequency from @(Double, Double)@. Otherwise, it is just concatenated to the 'OvertonesO'.+gAdd01 :: (Double,Double) -> Double -> (Double -> OvertonesO) -> OvertonesO+gAdd01 (note,ampl) freq f + | V.null . f $ freq = V.singleton (note,ampl)+ | otherwise =+    let v1 = renormF . f $ freq in+     let v2 = V.findIndices (\(x,_) -> x == note) $ v1 in+       if V.null v2 then V.cons (note,ampl) (f freq)+       else renormF . V.imap (\i (t,w) -> if i `V.elem` v2 then (t,w + ampl / fromIntegral (V.length v2)) else (t,w)) $ v1
dobutokO2.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                dobutokO2-version:             0.24.6.0+version:             0.25.0.0 synopsis:            A program and a library to create experimental music from a mono audio and a Ukrainian text description:         It can also create a timbre for the notes. Uses SoX inside. homepage:            https://hackage.haskell.org/package/dobutokO2