-- |
-- Module      :  MMSyn7l
-- Copyright   :  (c) OleksandrZhabenko 2020-2022, 2024
-- License     :  MIT
-- Stability   :  Experimental
-- Maintainer  :  oleksandr.zhabenko@yahoo.com
--
-- A program and a library to modify the amplitude of the sound representations for 
-- the Ukrainian language created by mmsyn7ukr package or somehow otherwise. Besides
-- it can be used to adjust volume for the sequential \"result*.wav\" files.
--

module MMSyn7l where

import qualified Data.List as L (sort,isPrefixOf,isSuffixOf)
import System.Directory
import Data.Char (toUpper, isDigit)
import qualified Sound.SoXBasics as SB
import qualified Sound.SoXBasics1 as SB1
import Data.Maybe (isJust)
import Control.Exception (onException)
import CaseBi.Arr (getBFstL')
import Sound.Control.Exception.FinalException
import System.Process
import System.Exit (ExitCode(ExitSuccess))
import EndOfExe2 (showE)
import Data.Maybe (fromJust)
import Numeric
import System.Info (os)

-- | Function 'changeVolume' is used to change the amplitude of the sound. 
-- For the proper proceeding you specify a @String@, which consists of 4 
-- digits (and it may be preceded by a symbol \"-\"). If the @String@ 
-- begins with the \"-\", then a sound amplitude decreases, otherwise 
-- the amplitude increases. The level of increase / decrease is 
-- determined by the magnitude of the absolute value of integer numbers. 
-- The greater is the number -- the greater is the amplitude change. 
-- The count begins with \"0000\" and ends with \"9999\" (the sign is not 
-- taken into consideration). If there is less than 4 digits in a @String@, 
-- then the @String@ is equivalent to that one with the appropriate number 
-- of zeroes preceding to fulfill to the 4 needed digits (for example, 
-- \"657\" is equivalent to \"0657\", \"-2\" is equivalent to \"-0002\" etc.) 
-- In such a case, for the @String@s without the 
-- initial sign \"-\" (the sound increases) an interval between the 
-- maximum by modulus value of the amlitude (which is represented by the 
-- parts of 1) and 1.0 is divided into 10 equal parts (starting a count 
-- from 0) and then that one of them is selected, which has a number 
-- determined by the first digit in the @String@ writing. Then (if specified 
-- further) the interval between this amplitude value and a value, 
-- which corresponds to the selection on the previous step the next 
-- first digit in the writing (for example, after \"4\" -- \"5\", 
-- after \"7\" -- \"8\" etc.), greater by 1 than the actually selected one, 
-- is also divided again into 10 equal parts and that one is selected, 
-- which corresponds to the number determined by the second digit in the 
-- String writing (again beginning with \"0\" and ending with \"9\") and so on 
-- until the 4th level. The greater exactness is not needed because our 
-- hearing ability hardly distinguish such a subtle sound changes. If 
-- the @String@ has as a first element the \'-\' @Char@ (the sound decreases), 
-- then everything is analogously the same, but an interval between the 
-- maximum by modulus amplitude value and 0.0 is divided into 10 equal parts 
-- and so on. 'Int' parameter is used to control the informational output
-- (to get it, specify 1). 
changeVolume ::  Int -> FilePath -> IO ()
changeVolume :: Int -> [Char] -> IO ()
changeVolume Int
n [Char]
file = do
  case (Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take Int
5 [Char]
os [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"mingw") of { Bool
True -> if Maybe [Char] -> Bool
forall a. Maybe a -> Bool
isJust ([Char] -> Maybe [Char]
showE [Char]
"sox") then [Char] -> [[Char]] -> [Char] -> IO (ExitCode, [Char], [Char])
readProcessWithExitCode (Maybe [Char] -> [Char]
forall a. HasCallStack => Maybe a -> a
fromJust ([Char] -> Maybe [Char]
showE [Char]
"sox"))
    [[Char]
file, [Char]
"-t", [Char]
"waveaudio", [Char]
"-d"] [Char]
"" IO (ExitCode, [Char], [Char]) -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return () else FinalException -> IO ()
catchEnd FinalException
ExecutableNotProperlyInstalled ; ~Bool
rrr -> if Maybe [Char] -> Bool
forall a. Maybe a -> Bool
isJust ([Char] -> Maybe [Char]
showE [Char]
"play") then [Char] -> [[Char]] -> [Char] -> IO (ExitCode, [Char], [Char])
readProcessWithExitCode (Maybe [Char] -> [Char]
forall a. HasCallStack => Maybe a -> a
fromJust ([Char] -> Maybe [Char]
showE [Char]
"play")) [[Char]
file] [Char]
"" IO (ExitCode, [Char], [Char]) -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return () else FinalException -> IO ()
catchEnd FinalException
ExecutableNotProperlyInstalled } -- Is taken from the mmsyn7ukr package as playA.
  case Int
n of
   Int
1 -> do 
    let sound :: [Char]
sound = [Char] -> [([Char], [Char])] -> [Char] -> [Char]
forall a b. Ord a => b -> [(a, b)] -> a -> b
getBFstL' [Char]
"е" ([[Char]] -> [[Char]] -> [([Char], [Char])]
forall a b. [a] -> [b] -> [(a, b)]
zip [[Char]
"A.wav", [Char]
"B.wav", [Char]
"C.wav", [Char]
"D.wav", [Char]
"E.wav", [Char]
"F.wav", [Char]
"G.wav", [Char]
"H.wav", 
         [Char]
"I.wav", [Char]
"J.wav", [Char]
"K.wav", [Char]
"L.wav", [Char]
"M.wav", [Char]
"N.wav", [Char]
"O.wav", [Char]
"P.wav", [Char]
"Q.wav", [Char]
"R.wav", 
          [Char]
"S.wav", [Char]
"T.wav", [Char]
"U.wav", [Char]
"V.wav", [Char]
"W.wav", [Char]
"X.wav", [Char]
"Y.wav", [Char]
"Z.wav", [Char]
"a.wav", [Char]
"b.wav", [Char]
"c.wav", 
            [Char]
"d.wav", [Char]
"e.wav", [Char]
"f.wav"] ([[Char]] -> [([Char], [Char])]) -> [[Char]] -> [([Char], [Char])]
forall a b. (a -> b) -> a -> b
$ [[Char]
"а",[Char]
"б",[Char]
"в",[Char]
"г",[Char]
"д",[Char]
"дж",[Char]
"дз", [Char]
"е",[Char]
"ж",[Char]
"з",[Char]
"и",[Char]
"й",[Char]
"к",[Char]
"л",[Char]
"м",[Char]
"н",[Char]
"о",[Char]
"п",[Char]
"р",
              [Char]
"с",[Char]
"сь",[Char]
"т",[Char]
"у",[Char]
"ф",[Char]
"х",[Char]
"ц",[Char]
"ць",[Char]
"ч",[Char]
"ш",[Char]
"ь",[Char]
"і",[Char]
"ґ"]) [Char]
file
    [Char] -> IO ()
putStrLn ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
"You can now change the volume for the played sound representation for the Ukrainian sound " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> [Char]
forall a. Show a => a -> [Char]
show ((Char -> Char) -> [Char] -> [Char]
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper [Char]
sound)
    [Char] -> IO ()
putStrLn [Char]
""
    [Char] -> IO ()
putStr [Char]
"Please, specify the change by passing a String of digits (with may be a preceding symbol \'-\'). "
    [Char] -> IO ()
putStr [Char]
""
    [Char] -> IO ()
putStr [Char]
"For the proper proceeding you specify a String, which consists of 4 "
    [Char] -> IO ()
putStr [Char]
"digits (and it may be preceded by a symbol \"-\"). If the String "
    [Char] -> IO ()
putStr [Char]
"begins with the \"-\", then a sound amplitude decreases, otherwise "
    [Char] -> IO ()
putStr [Char]
"the amplitude increases. The level of increase / decrease is "
    [Char] -> IO ()
putStr [Char]
"determined by the magnitude of the absolute value of integer numbers. "
    [Char] -> IO ()
putStr [Char]
"The greater is the number -- the greater is the amplitude change. "
    [Char] -> IO ()
putStr [Char]
"The count begins with \"0000\" and ends with \"9999\" (the sign is not "
    [Char] -> IO ()
putStr [Char]
"taken into consideration). If there is less than 4 digits in a String, "
    [Char] -> IO ()
putStr [Char]
"then the String is equivalent to that one with the appropriate number "
    [Char] -> IO ()
putStr [Char]
"of zeroes preceding to fulfill to the 4 needed digits (for example, "
    [Char] -> IO ()
putStr [Char]
"\"657\" is equivalent to \"0657\", \"-2\" is equivalent to \"-0002\" etc.). "
    [Char] -> IO ()
putStr [Char]
"In such a case, for the Strings without the "
    [Char] -> IO ()
putStr [Char]
"initial sign \"-\" (the sound increases) an interval between the "
    [Char] -> IO ()
putStr [Char]
"maximum by modulus value of the amlitude (which is represented by the "
    [Char] -> IO ()
putStr [Char]
"parts of 1) and 1.0 is divided into 10 equal parts (starting a count "
    [Char] -> IO ()
putStr [Char]
"from 0) and then that one of them is selected, which has a number "
    [Char] -> IO ()
putStr [Char]
"determined by the first digit in the String writing. Then (if specified "
    [Char] -> IO ()
putStr [Char]
"further) the interval between this amplitude value and a value, "
    [Char] -> IO ()
putStr [Char]
"which corresponds to the selection on the previous step the next "
    [Char] -> IO ()
putStr [Char]
"first digit in the writing (for example, after \"4\" -- \"5\", "
    [Char] -> IO ()
putStr [Char]
"after \"7\" -- \"8\" etc.), greater by 1 than the actually selected one, "
    [Char] -> IO ()
putStr [Char]
"is also divided again into 10 equal parts and that one is selected, "
    [Char] -> IO ()
putStr [Char]
"which corresponds to the number determined by the second digit in the "
    [Char] -> IO ()
putStr [Char]
"String writing (again beginning with \"0\" and ending with \"9\") and so on "
    [Char] -> IO ()
putStr [Char]
"until the 4th level. The greater exactness is not needed because our "
    [Char] -> IO ()
putStr [Char]
"hearing ability hardly distinguish such a subtle sound changes. If "
    [Char] -> IO ()
putStr [Char]
"the String has as a first element the \'-\' Char (the sound decreases), "
    [Char] -> IO ()
putStr [Char]
"then everything is analogously the same, but an interval between the "
    [Char] -> IO ()
putStr [Char]
"maximum by modulus amplitude value and 0.0 is divided into 10 equal parts "
    [Char] -> IO ()
putStrLn [Char]
"and so on. "
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException ([Char] -> IO ()
specifyVol [Char]
file) (do
      [Char] -> IO ()
putStrLn [Char]
""
      [Char] -> IO ()
putStrLn [Char]
"Something went wrong for the sound representation, please, check the input value and repeat once more! "
      [Char] -> IO ()
specifyVol [Char]
file)
   Int
_ -> IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException ([Char] -> IO ()
specifyVol [Char]
file) (do
         [Char] -> IO ()
putStrLn [Char]
""
         [Char] -> IO ()
putStrLn [Char]
"Something went wrong for the sound representation, please, check the input value and repeat once more! "
         [Char] -> IO ()
specifyVol [Char]
file)

-- | Function 'specifyVol' is used internally in the 'changeVolume' to get the @String@ and to apply the needed change. 
specifyVol :: FilePath -> IO ()
specifyVol :: [Char] -> IO ()
specifyVol [Char]
file = do   
  [Char]
change0 <- IO [Char]
getLine
  Int
upperbound <- [Char] -> IO Int
SB.upperBnd [Char]
file
  ([Char]
originalStr, Bool
bool) <- [Char] -> (Int, Int) -> IO ([Char], Bool)
SB.selMaxAbs [Char]
file (Int
0::Int, Int
upperbound)
  if Bool
bool 
    then [Char] -> ([Char], [Char]) -> IO ()
changeVol3 [Char]
file ([Char]
change0, [Char]
originalStr)
    else [Char] -> ([Char], [Char]) -> IO ()
changeVol4 [Char]
file ([Char]
change0, [Char]
originalStr)

-- | Function 'changeVol2' is used internally in the 'specifyVol' in case of decreasing of the sound.
changeVol2 :: FilePath -> String -> Float -> IO ()
changeVol2 :: [Char] -> [Char] -> Float -> IO ()
changeVol2 [Char]
file [Char]
xs Float
ampl = do 
  let ys :: [Char]
ys = Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take Int
4 ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
filter Char -> Bool
isDigit ([Char] -> [Char]) -> [Char] -> [Char]
forall a b. (a -> b) -> a -> b
$ [Char]
xs
      coefA :: Float
coefA = Float
0.0001 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Int -> Float
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Char] -> Int
forall a. Read a => [Char] -> a
read [Char]
ys::Int)
      ratio :: Float
ratio = Float
1.0 Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
coefA
  [Char] -> Float -> IO ()
SB1.volS [Char]
file (Float
ratio Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
ampl)
  
-- | Function 'changeVol3' is used internally in the 'specifyVol' in case of working with the maximum amplitude.
changeVol3 :: FilePath -> (String, String) -> IO ()
changeVol3 :: [Char] -> ([Char], [Char]) -> IO ()
changeVol3 [Char]
file ([Char]
change0, [Char]
originalStr) = do
  let ampl :: Float
ampl = [Char] -> Float
forall a. Read a => [Char] -> a
read [Char]
originalStr::Float
  if Float
ampl Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
> Float
0.0 
    then do 
      let delta :: Float
delta = Float
1.0 Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
ampl
          xs :: [Char]
xs = (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
filter (\Char
x -> Char -> Bool
isDigit Char
x Bool -> Bool -> Bool
|| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-') [Char]
change0
      if Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take Int
1 [Char]
xs [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"-" 
        then [Char] -> [Char] -> Float -> IO ()
changeVol2 [Char]
file [Char]
xs Float
ampl
        else do 
          let ys :: [Char]
ys = Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take Int
4 ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Char -> Bool
isDigit) ([Char] -> [Char]) -> [Char] -> [Char]
forall a b. (a -> b) -> a -> b
$ [Char]
xs
              coefA :: Float
coefA = Float
0.0001 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Int -> Float
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Char] -> Int
forall a. Read a => [Char] -> a
read [Char]
ys::Int)
              ratio :: Float
ratio = Float
1.0 Float -> Float -> Float
forall a. Num a => a -> a -> a
+ (Float
delta Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
ampl) Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
coefA
          [Char] -> Float -> IO ()
SB1.volS [Char]
file (Float
ratio Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
ampl)
    else FinalException -> IO ()
catchEnd ([Char] -> [Char] -> FinalException
StrangeAnswer [Char]
"Sound.SoXBasics1" [Char]
"volS")

-- | Function 'changeVol4' is used internally in the 'specifyVol' in case of working with the minimum amplitude.
changeVol4 :: FilePath -> (String, String) -> IO ()
changeVol4 :: [Char] -> ([Char], [Char]) -> IO ()
changeVol4 [Char]
file ([Char]
change0, [Char]
originalStr) = do
  let ampl :: Float
ampl = [Char] -> Float
forall a. Read a => [Char] -> a
read [Char]
originalStr::Float
  if Float
ampl Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
< Float
0.0
    then do 
      let delta :: Float
delta = (-Float
1.0) Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
ampl
          xs :: [Char]
xs = (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
filter (\Char
x -> Char -> Bool
isDigit Char
x Bool -> Bool -> Bool
|| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-') [Char]
change0
      if Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take Int
1 [Char]
xs [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"-" 
        then [Char] -> [Char] -> Float -> IO ()
changeVol2 [Char]
file [Char]
xs Float
ampl
        else do 
          let ys :: [Char]
ys = Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take Int
4 ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
filter Char -> Bool
isDigit ([Char] -> [Char]) -> [Char] -> [Char]
forall a b. (a -> b) -> a -> b
$ [Char]
xs
              coefA :: Float
coefA = Float
0.0001 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Int -> Float
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Char] -> Int
forall a. Read a => [Char] -> a
read [Char]
ys::Int)
              ratio :: Float
ratio = Float
1.0 Float -> Float -> Float
forall a. Num a => a -> a -> a
+ (Float
delta Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
ampl) Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
coefA
          [Char] -> Float -> IO ()
SB1.volS [Char]
file (Float
ratio Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
ampl)
    else FinalException -> IO ()
catchEnd ([Char] -> [Char] -> FinalException
StrangeAnswer [Char]
"Sound.SoXBasics1" [Char]
"volS")

-- | Works with the \"result*.wav\" files in the current directory: it adjusts volume levels for the sequence of them starting from the 
-- first argument in a list and ending with the second one (if specified). If there is no first -- all such files are adjusted; if there is no second one -- 
-- the files are adjusted to the last one. Count starts at 0. 
adjustVolRes :: [String] -> IO ()
adjustVolRes :: [[Char]] -> IO ()
adjustVolRes [[Char]]
args = do
  [[Char]]
dir <- [Char] -> IO [[Char]]
listDirectory [Char]
"."
  let dirV0 :: [[Char]]
dirV0 = [[Char]] -> [[Char]]
forall a. Ord a => [a] -> [a]
L.sort ([[Char]] -> [[Char]])
-> ([[Char]] -> [[Char]]) -> [[Char]] -> [[Char]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char] -> Bool) -> [[Char]] -> [[Char]]
forall a. (a -> Bool) -> [a] -> [a]
filter ([Char] -> [Char] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
L.isPrefixOf [Char]
"result") ([[Char]] -> [[Char]]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> a -> b
$ [[Char]]
dir
      first0 :: [Char]
first0 = [[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Char]] -> [Char])
-> ([[Char]] -> [[Char]]) -> [[Char]] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [[Char]] -> [[Char]]
forall a. Int -> [a] -> [a]
take Int
1 ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ [[Char]]
args
      last0 :: [Char]
last0  = [[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Char]] -> [Char])
-> ([[Char]] -> [[Char]]) -> [[Char]] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [[Char]] -> [[Char]]
forall a. Int -> [a] -> [a]
take Int
1 ([[Char]] -> [[Char]])
-> ([[Char]] -> [[Char]]) -> [[Char]] -> [[Char]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [[Char]] -> [[Char]]
forall a. Int -> [a] -> [a]
drop Int
1 ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ [[Char]]
args
      idxAllN :: Int
idxAllN = [[Char]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Char]]
dirV0 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
  IO () -> IO Any -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do { 
    let first1 :: Int
first1 = [Char] -> Int
forall a. Read a => [Char] -> a
read [Char]
first0::Int
        last1 :: Int
last1 = [Char] -> Int
forall a. Read a => [Char] -> a
read [Char]
last0::Int
        first2 :: Int
first2 = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min (Int -> Int
forall a. Num a => a -> a
abs Int
first1) (Int -> Int
forall a. Num a => a -> a
abs Int
last1)
        last2 :: Int
last2 = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max (Int -> Int
forall a. Num a => a -> a
abs Int
first1) (Int -> Int
forall a. Num a => a -> a
abs Int
last1)
        first :: Int
first
         | Int
first2 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
idxAllN = Int
0
         | Bool
otherwise = Int
first2
        l :: Int
l =  if Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
last2 Int
idxAllN Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
GT then Int
idxAllN Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
first Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 else Int
last2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
first Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
     ; ([Char] -> IO ()) -> [[Char]] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Int -> [Char] -> IO ()
changeVolume Int
1) ([[Char]] -> IO ()) -> ([[Char]] -> [[Char]]) -> [[Char]] -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [[Char]] -> [[Char]]
forall a. Int -> [a] -> [a]
take Int
l ([[Char]] -> [[Char]])
-> ([[Char]] -> [[Char]]) -> [[Char]] -> [[Char]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [[Char]] -> [[Char]]
forall a. Int -> [a] -> [a]
drop Int
first ([[Char]] -> IO ()) -> [[Char]] -> IO ()
forall a b. (a -> b) -> a -> b
$ [[Char]]
dirV0
     ; [Char] -> IO ()
putStrLn [Char]
""
     ; [Char] -> IO ()
putStrLn [Char]
"Now you have changed (or left unchanged) the amplitudes for the needed \"result*.wav\" sound files." }) (do
         [Char] -> IO Any
forall a. HasCallStack => [Char] -> a
error [Char]
"Please, specify a right numbers for the first and last files to be adjusted starting count from 0.")

-----------------------------------------------------------------------------------------------

-- Taken from the DobutokO.Sound.IntermediateF module here so that they are more used this way.  

-- | Takes a filename to be applied a SoX chain of effects (or just one) as list of 'String' (the second argument). Produces the temporary
-- new file with the name ((name-of-the-file) ++ (\"effects.wav\"  OR \"effects.flac\") -- the type is preserved), which then is removed. 
--
-- The syntaxis is that every separate literal for SoX must be a new element in the list. Please, for more information, refer to SoX documentation.
-- Please, check by yourself whether you have enough permissions to read and write to the 'FilePath'-specified
-- file and to the containing it directory. The function is not intended to be used in otherwise cases.
soxE :: FilePath -> [String] -> IO ()
soxE :: [Char] -> [[Char]] -> IO ()
soxE [Char]
file [[Char]]
arggs = do
  (ExitCode
code,[Char]
_,[Char]
_) <- [Char] -> [[Char]] -> [Char] -> IO (ExitCode, [Char], [Char])
readProcessWithExitCode (Maybe [Char] -> [Char]
forall a. HasCallStack => Maybe a -> a
fromJust ([Char] -> Maybe [Char]
showE [Char]
"sox")) ([[Char]
file,[Char]
file [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"effects" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> [Char]
efw2 [Char]
file] [[Char]] -> [[Char]] -> [[Char]]
forall a. [a] -> [a] -> [a]
++ [[Char]]
arggs) [Char]
""
  case ExitCode
code of
    ExitCode
ExitSuccess -> [Char] -> [Char] -> IO ()
renameFile ([Char]
file [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"effects" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> [Char]
efw2 [Char]
file) [Char]
file
    ExitCode
_ -> do
       [Char] -> IO ()
removeFile ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
file [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"effects" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> [Char]
efw2 [Char]
file
       [Char] -> IO ()
putStrLn ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
"MMSyn7l.soxE \"" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
file [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"\" has not been successful. The file has not been changed at all. "

-- | Applies \"fade q\" effect to both ends of the supported by SoX sound file 'FilePath' so that concatenating them consequently after such application 
-- leads to no clipping. Otherwise, the clipping exists if not prevented by may be some other means. For more information, please, refer to the
-- SoX documentation.
fadeEnds :: FilePath -> IO ()
fadeEnds :: [Char] -> IO ()
fadeEnds = Int -> [Char] -> IO ()
fadeEndsMilN Int
10

-- | Applies \"fade q\" effect to both ends of the supported by SoX sound file 'FilePath' so that concatenating them consequently after such application 
-- leads to no clipping. Otherwise, the clipping exists if not prevented by may be some other means. The duration of the changes are in 5 times 
-- smaller than for 'fadeEnds' function and is equal to 0.002 sec. For more information, please, refer to the SoX documentation.
fadeEndsMil2 :: FilePath -> IO ()
fadeEndsMil2 :: [Char] -> IO ()
fadeEndsMil2 = Int -> [Char] -> IO ()
fadeEndsMilN Int
2

-- | Applies \"fade q\" effect to both ends of the supported by SoX sound file 'FilePath' so that concatenating them consequently after such application 
-- leads to no clipping. Otherwise, the clipping exists if not prevented by may be some other means. The duration of the changes are usually 
-- smaller than for 'fadeEnds' function and is equal to 0.001 \* n sec (where n is in range [1..10]). 
-- For more information, please, refer to the SoX documentation.
fadeEndsMilN :: Int -> FilePath -> IO ()
fadeEndsMilN :: Int -> [Char] -> IO ()
fadeEndsMilN Int
n [Char]
file = [Char] -> [[Char]] -> IO ()
soxE [Char]
file [[Char]
"fade",[Char]
"q", Maybe Int -> Double -> [Char] -> [Char]
forall a. RealFloat a => Maybe Int -> a -> [Char] -> [Char]
showFFloat (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
4) (if (Int
n Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
11) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0 then Double
0.001 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
n Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
11) else Double
0.002) [Char]
"",[Char]
"-0.0"]

-- | Applies \"fade\" effect (the type is specified by the 'Char' argument, for more information, please, refer to the SoX documentation) to the both ends 
-- of the sound with header (supported by SoX). The 'Float' arguments specify the percentages of the length of the sound that is faded-in and faded-out 
-- respectively. Otherwise, the function returns an error.
fadeEndsTMN :: Char -> Float -> Float -> FilePath -> IO ()
fadeEndsTMN :: Char -> Float -> Float -> [Char] -> IO ()
fadeEndsTMN Char
c Float
per1 Float
per2 [Char]
file 
 | Float -> Float -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Float
per1 Float
0 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
GT Bool -> Bool -> Bool
&& Float -> Float -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Float
per2 Float
0 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
GT Bool -> Bool -> Bool
&& Float -> Float -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Float
per1 Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
per2) Float
100 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
/= Ordering
GT = do
    Float
d0 <- [Char] -> IO Float
SB.durationA [Char]
file
    [Char] -> [[Char]] -> IO ()
soxE [Char]
file [[Char]
"fade", [Char] -> [(Char, [Char])] -> Char -> [Char]
forall a b. Ord a => b -> [(a, b)] -> a -> b
getBFstL' [Char]
"l" [(Char
'h',[Char]
"h"),(Char
'p',[Char]
"p"),(Char
'q',[Char]
"q"),(Char
't',[Char]
"t")] Char
c, Maybe Int -> Float -> [Char] -> [Char]
forall a. RealFloat a => Maybe Int -> a -> [Char] -> [Char]
showFFloat (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
4) (Float
d0 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
per1 Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
100.0) [Char]
"",[Char]
"-0.0", 
      Maybe Int -> Float -> [Char] -> [Char]
forall a. RealFloat a => Maybe Int -> a -> [Char] -> [Char]
showFFloat (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
4) (Float
d0 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
per2 Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
100.0) [Char]
""]
 | Bool
otherwise = [Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
"MMSyn7l.fadeEndsTMN: the percentages sum is out of the (0..100] range. "

-- | Variant of the 'fadeEndsTMN' with the both equal percentages specified by the 'Float' argument. It must be in the range (0..50]. Otherwise, the function 
-- returns error.
fadeEndsTMB :: Char -> Float -> FilePath -> IO ()
fadeEndsTMB :: Char -> Float -> [Char] -> IO ()
fadeEndsTMB Char
c Float
per 
 | Float -> Float -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Float
per Float
0 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
GT Bool -> Bool -> Bool
&& Float -> Float -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Float
per Float
50 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
/= Ordering
GT = Char -> Float -> Float -> [Char] -> IO ()
fadeEndsTMN Char
c Float
per Float
per
 | Bool
otherwise = [Char] -> [Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
"MMSyn7l.fadeEndsTMB: the percentage is out of the (0..50] range. "

------------------------------------------------------------------------------------------------------

-- New functions with usage of the moved here fadeEnds* and 'soxE' functions.

-- | Using a new function 'fadeEndsMil2' fades the ends of the .wav files in the current directory.
fadeWav002 :: IO ()
fadeWav002 :: IO ()
fadeWav002 = do
  [[Char]]
dir0 <- ([[Char]] -> [[Char]]) -> IO [[Char]] -> IO [[Char]]
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([Char] -> Bool) -> [[Char]] -> [[Char]]
forall a. (a -> Bool) -> [a] -> [a]
filter ([Char] -> [Char] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`L.isSuffixOf` [Char]
".wav")) (IO [[Char]] -> IO [[Char]])
-> ([Char] -> IO [[Char]]) -> [Char] -> IO [[Char]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> IO [[Char]]
listDirectory ([Char] -> IO [[Char]]) -> [Char] -> IO [[Char]]
forall a b. (a -> b) -> a -> b
$ [Char]
"."
  ([Char] -> IO ()) -> [[Char]] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ [Char] -> IO ()
fadeEndsMil2 [[Char]]
dir0

-- | Using a new function 'fadeEndsMilN' fades the ends of the .wav files in the current directory. The first argument is the 'Int' argument 
-- for the 'fadeEndsMilN' and is a number of milliseconds to be used for fading (usually from 1 to 10). 
fadeWavN :: Int -> IO ()
fadeWavN :: Int -> IO ()
fadeWavN Int
n = do
  [[Char]]
dir0 <- ([[Char]] -> [[Char]]) -> IO [[Char]] -> IO [[Char]]
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([Char] -> Bool) -> [[Char]] -> [[Char]]
forall a. (a -> Bool) -> [a] -> [a]
filter ([Char] -> [Char] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`L.isSuffixOf` [Char]
".wav")) (IO [[Char]] -> IO [[Char]])
-> ([Char] -> IO [[Char]]) -> [Char] -> IO [[Char]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> IO [[Char]]
listDirectory ([Char] -> IO [[Char]]) -> [Char] -> IO [[Char]]
forall a b. (a -> b) -> a -> b
$ [Char]
"."
  ([Char] -> IO ()) -> [[Char]] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Int -> [Char] -> IO ()
fadeEndsMilN Int
n) [[Char]]
dir0        

-- | Converts WAV file to FLAC file using SoX (please, check before whether your installation supports FLAC files) using possible rate and bit depth
-- conversion accordingly to 'soxBasicParams' format. If the conversion is successful ('ExitCode' is 'ExitSuccess') then removes the primary file.
wavToFlac :: String -> FilePath -> IO ()
wavToFlac :: [Char] -> [Char] -> IO ()
wavToFlac [Char]
ys [Char]
file = do
  let ([Char]
ts,[Char]
zs) = Int -> [Char] -> ([Char], [Char])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
2 ([Char] -> ([Char], [Char]))
-> ([Char] -> [Char]) -> [Char] -> ([Char], [Char])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char]
forall a. HasCallStack => [a] -> [a]
init ([Char] -> ([Char], [Char])) -> [Char] -> ([Char], [Char])
forall a b. (a -> b) -> a -> b
$ [Char]
ys
  (ExitCode
code,[Char]
_,[Char]
herr) <- [Char] -> [[Char]] -> [Char] -> IO (ExitCode, [Char], [Char])
readProcessWithExitCode (Maybe [Char] -> [Char]
forall a. HasCallStack => Maybe a -> a
fromJust ([Char] -> Maybe [Char]
showE [Char]
"sox")) [[Char]
file,[Char] -> [([Char], [Char])] -> [Char] -> [Char]
forall a b. Ord a => b -> [(a, b)] -> a -> b
getBFstL' [Char]
"-r22050" ([[Char]] -> [[Char]] -> [([Char], [Char])]
forall a b. [a] -> [b] -> [(a, b)]
zip [[Char]
"11",[Char]
"16", [Char]
"17", [Char]
"19", [Char]
"32", [Char]
"44", [Char]
"48",
     [Char]
"80", [Char]
"96"] [[Char]
"-r11025",[Char]
"-r16000",[Char]
"-r176400",[Char]
"-r192000",[Char]
"-r32000",[Char]
"-r44100",[Char]
"-r48000",[Char]
"-r8000",[Char]
"-r96000"]) [Char]
ts, if [Char]
zs [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"2" then [Char]
"-b24"
       else [Char]
"-b16",Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
3) [Char]
file [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"flac"] [Char]
""
  case ExitCode
code of
    ExitCode
ExitSuccess -> [Char] -> IO ()
removeFile [Char]
file
    ExitCode
_           -> do
      [Char] -> IO ()
putStrLn ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
"MMSyn7l.wavToFlac: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
herr
      Bool
exi <- [Char] -> IO Bool
doesFileExist ([Char] -> IO Bool) -> [Char] -> IO Bool
forall a b. (a -> b) -> a -> b
$ Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
3) [Char]
file [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"flac"
      if Bool
exi then [Char] -> IO ()
removeFile (Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
3) [Char]
file [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"flac") IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
""
      else [Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
""

-- | Converts FLAC file to WAV file using SoX (please, check before whether your installation supports FLAC files) using possible rate and bit depth
-- conversion accordingly to 'soxBasicParams' format. If the conversion is successful ('ExitCode' is 'ExitSuccess') then removes the primary file.
flacToWav :: String -> FilePath -> IO ()
flacToWav :: [Char] -> [Char] -> IO ()
flacToWav [Char]
ys [Char]
file = do
  let ([Char]
ts,[Char]
zs) = Int -> [Char] -> ([Char], [Char])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
2 ([Char] -> ([Char], [Char]))
-> ([Char] -> [Char]) -> [Char] -> ([Char], [Char])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char]
forall a. HasCallStack => [a] -> [a]
init ([Char] -> ([Char], [Char])) -> [Char] -> ([Char], [Char])
forall a b. (a -> b) -> a -> b
$ [Char]
ys
  (ExitCode
code,[Char]
_,[Char]
herr) <- [Char] -> [[Char]] -> [Char] -> IO (ExitCode, [Char], [Char])
readProcessWithExitCode (Maybe [Char] -> [Char]
forall a. HasCallStack => Maybe a -> a
fromJust ([Char] -> Maybe [Char]
showE [Char]
"sox")) [[Char]
file,[Char] -> [([Char], [Char])] -> [Char] -> [Char]
forall a b. Ord a => b -> [(a, b)] -> a -> b
getBFstL' [Char]
"-r22050" ([[Char]] -> [[Char]] -> [([Char], [Char])]
forall a b. [a] -> [b] -> [(a, b)]
zip [[Char]
"11",[Char]
"16", [Char]
"17", [Char]
"19", [Char]
"32", [Char]
"44", [Char]
"48",
     [Char]
"80", [Char]
"96"] [[Char]
"-r11025",[Char]
"-r16000",[Char]
"-r176400",[Char]
"-r192000",[Char]
"-r32000",[Char]
"-r44100",[Char]
"-r48000",[Char]
"-r8000",[Char]
"-r96000"]) [Char]
ts, if [Char]
zs [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"2" then [Char]
"-b24"
       else [Char]
"-b16",Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
4) [Char]
file [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"wav"] [Char]
""
  case ExitCode
code of
    ExitCode
ExitSuccess -> [Char] -> IO ()
removeFile [Char]
file
    ExitCode
_           -> do
      [Char] -> IO ()
putStrLn ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
"MMSyn7l.flacToWav: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
herr
      Bool
exi <- [Char] -> IO Bool
doesFileExist ([Char] -> IO Bool) -> [Char] -> IO Bool
forall a b. (a -> b) -> a -> b
$ Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
4) [Char]
file [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"wav"
      if Bool
exi then [Char] -> IO ()
removeFile (Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
4) [Char]
file [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"wav") IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
""
      else [Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
""      

w2f :: FilePath -> FilePath
w2f :: [Char] -> [Char]
w2f [Char]
file = let ([Char]
zs,[Char]
ts) = Int -> [Char] -> ([Char], [Char])
forall a. Int -> [a] -> ([a], [a])
splitAt ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
4) [Char]
file in if [Char]
ts [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
".wav" then [Char]
zs [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
".flac" else [Char] -> [Char]
forall a. HasCallStack => [Char] -> a
error [Char]
"You give not a WAV file! "
     
f2w :: FilePath -> FilePath
f2w :: [Char] -> [Char]
f2w [Char]
file = let ([Char]
zs,[Char]
ts) = Int -> [Char] -> ([Char], [Char])
forall a. Int -> [a] -> ([a], [a])
splitAt ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
5) [Char]
file in if [Char]
ts [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
".flac" then [Char]
zs [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
".wav" else [Char] -> [Char]
forall a. HasCallStack => [Char] -> a
error [Char]
"You give not a FLAC file! "

wOrf :: FilePath -> String
wOrf :: [Char] -> [Char]
wOrf [Char]
file = let us :: [Char]
us = Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
drop ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
4) [Char]
file in case [Char]
us of { [Char]
".wav" -> [Char]
"w" ; [Char]
"flac" -> [Char]
"f" ;
  ~[Char]
bbb -> [Char] -> [Char]
forall a. HasCallStack => [Char] -> a
error [Char]
"You give neither a WAV nor a FLAC file! " }

cfw2wf :: FilePath -> FilePath
cfw2wf :: [Char] -> [Char]
cfw2wf [Char]
file
 | [Char] -> [Char]
wOrf [Char]
file [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"w" = [Char] -> [Char]
w2f [Char]
file
 | [Char] -> [Char]
wOrf [Char]
file [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"f" = [Char] -> [Char]
f2w [Char]
file
 | Bool
otherwise = [Char] -> [Char]
forall a. HasCallStack => [Char] -> a
error [Char]
"You give neither a WAV nor a FLAC file! "

efw2 :: FilePath -> String
efw2 :: [Char] -> [Char]
efw2 [Char]
file = let us :: [Char]
us = Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
drop ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
4) [Char]
file in case [Char]
us of { [Char]
".wav" -> [Char]
".wav" ; [Char]
"flac" -> [Char]
".flac" ;
  ~[Char]
bbb -> [Char] -> [Char]
forall a. HasCallStack => [Char] -> a
error [Char]
"You give neither a WAV nor a FLAC file! " }

efw2vv :: FilePath -> String
efw2vv :: [Char] -> [Char]
efw2vv [Char]
file = let us :: [Char]
us = Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
drop ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
file Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
4) [Char]
file in case [Char]
us of { [Char]
".wav" -> [Char]
".flac" ; [Char]
"flac" -> [Char]
".wav" ;
  ~[Char]
bbb -> [Char] -> [Char]
forall a. HasCallStack => [Char] -> a
error [Char]
"You give neither a WAV nor a FLAC file! " }