Skip to content

Commit 1b1a885

Browse files
Use mpg123 --remote-err, drop errorLoop thread.
1 parent ff058cb commit 1b1a885

2 files changed

Lines changed: 6 additions & 18 deletions

File tree

Core.hs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import Data.Tuple (swap)
3939
import Control.Monad.State.Strict
4040
import System.Directory (doesFileExist, findExecutable, createDirectoryIfMissing,
4141
getXdgDirectory, XdgDirectory(..))
42-
import System.IO (hPutStrLn, hGetLine, stderr)
42+
import System.IO (hPutStrLn, stderr)
4343
import System.Process (runInteractiveProcess, waitForProcess)
4444
import System.Clock (TimeSpec(..), diffTimeSpec)
4545
import System.Random (randomR, newStdGen)
@@ -85,7 +85,6 @@ start opts (Playlist folders music) = do
8585
, mpgInput
8686
, refreshLoop
8787
, uptimeLoop
88-
, errorLoop
8988
]
9089

9190
putMVar hState HState
@@ -158,12 +157,12 @@ mpgLoop = runForever do
158157
case mmpg of
159158
Nothing -> shutdown $ Just $ "Cannot find " ++ mp3Tool ++ " in path"
160159
Just mppath -> do
161-
mv <- try $ runInteractiveProcess mppath ["-R", "-"] Nothing Nothing
160+
mv <- try $ runInteractiveProcess mppath ["-R", "--remote-err"] Nothing Nothing
162161
case mv of
163162
Left (ex :: SomeException) ->
164163
warnA $ mppath ++ " failed to start; retrying: " ++ show ex
165164

166-
Right (writeh, readh, errh, pid) -> do
165+
Right (writeh, _, errh, pid) -> do
167166
ct <- modifyHS $ \st -> let sp = spawns st + 1 in (st
168167
{ mpgPid = Just pid
169168
, status = Stopped
@@ -172,7 +171,7 @@ mpgLoop = runForever do
172171
, spawns = sp
173172
}, sp)
174173

175-
putMVar mpg Mpg { readh, errh, writeh }
174+
putMVar mpg Mpg { errh, writeh }
176175

177176
when (ct > 1) $ warnA $ mp3Tool ++ " #" ++ show ct ++ ": Ready"
178177
catch @SomeException (void $ waitForProcess pid) (const $ pure ())
@@ -229,20 +228,13 @@ showTimeDiff = showTimeDiff_ False
229228

230229
------------------------------------------------------------------------
231230

232-
-- | Handle, and display errors produced by mpg123
233-
errorLoop :: IO ()
234-
errorLoop = runForever $
235-
readMVar mpg <&> errh >>= hGetLine >>= (warnA . ("mpg123 err: " ++))
236-
237-
------------------------------------------------------------------------
238-
239231
-- | Handle messages arriving over a pipe from the decoder process. When
240232
-- shutdown kills the other end of the pipe, hGetLine will fail, so we
241233
-- take that chance to exit.
242234
--
243235
mpgInput :: IO ()
244236
mpgInput = runForever $ do
245-
line <- P.hGetLine =<< readh <$> readMVar mpg
237+
line <- P.hGetLine =<< errh <$> readMVar mpg
246238
case mpgParser line of
247239
Right m -> handleMsg m
248240
Left (Just e) -> warnA ("mpg123: " ++ e)

State.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ setModified = void $ tryPutMVar modified ()
8181
------------------------------------------------------------------------
8282
-- The decoder.
8383

84-
data Mpg = Mpg
85-
{ writeh :: !Handle
86-
, readh :: !Handle
87-
, errh :: !Handle
88-
}
84+
data Mpg = Mpg { errh :: !Handle, writeh :: !Handle }
8985

9086
mpg :: MVar Mpg
9187
mpg = unsafePerformIO newEmptyMVar

0 commit comments

Comments
 (0)