Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ejconlon committed Sep 5, 2024
1 parent acd9f36 commit 78398e2
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 100 deletions.
3 changes: 1 addition & 2 deletions minipat-midi/src/Minipat/Midi/Boot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ module Minipat.Midi.Boot
)
where

import Minipat.Midi.Midi (PortMsg)
import Data.Sequence (Seq)
import Data.Text (Text)
import Minipat.Live.Boot
import Minipat.Live.Datum (DatumProxy (..))
import Minipat.Live.Extra (Note, parseDatum, parseMidiNote, parseNote)
import Minipat.Midi.Convert (Vel (..))
import Minipat.Midi.Impl qualified as I
import Minipat.Midi.Midi (PortName (..))
import Minipat.Midi.Midi (PortMsg, PortName (..))

type MidiLiveSt = (LiveSt, LiveBackend ~ I.MidiBackend)

Expand Down
25 changes: 12 additions & 13 deletions minipat-midi/src/Minipat/Midi/Count.hs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
module Minipat.Midi.Count where

import Control.Monad (when)
import Control.Exception (Exception)
import Control.Monad (when)
import Control.Monad.Catch (MonadThrow (..))
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Reader (MonadReader, ReaderT (..))
import Control.Monad.Writer (MonadWriter (..), WriterT (..))
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Control.Monad.Reader (ReaderT (..), MonadReader)
import Control.Monad.Writer (WriterT (..), MonadWriter (..))
import Data.Typeable (Typeable)
import Control.Monad.Catch (MonadThrow (..))

newtype ErrCounts e = ErrCounts { unErrCounts :: Map e Int }
newtype ErrCounts e = ErrCounts {unErrCounts :: Map e Int}
deriving stock (Eq, Ord, Show)

instance (Show e, Typeable e) => Exception (ErrCounts e)

instance Ord e => Semigroup (ErrCounts e) where
instance (Ord e) => Semigroup (ErrCounts e) where
ErrCounts m1 <> ErrCounts m2 = ErrCounts (Map.unionWith (+) m1 m2)

instance Ord e => Monoid (ErrCounts e) where
instance (Ord e) => Monoid (ErrCounts e) where
mempty = ErrCounts Map.empty

countErr :: e -> ErrCounts e
Expand All @@ -27,15 +27,14 @@ countErr e = ErrCounts (Map.singleton e 1)
hasErrs :: ErrCounts e -> Bool
hasErrs = not . Map.null . unErrCounts

rethrowCounts :: (Show e, Typeable e) => MonadThrow m => ErrCounts e -> m ()
rethrowCounts :: (Show e, Typeable e) => (MonadThrow m) => ErrCounts e -> m ()
rethrowCounts c = when (hasErrs c) (throwM c)

newtype CountM e r a = CountM { unCountM :: ReaderT r (WriterT (ErrCounts e) IO) a }
newtype CountM e r a = CountM {unCountM :: ReaderT r (WriterT (ErrCounts e) IO) a}
deriving newtype (Functor, Applicative, Monad, MonadIO, MonadReader r, MonadWriter (ErrCounts e))

countErrM :: Ord e => e -> CountM e s ()
countErrM = tell . countErr
throwErrM :: (Ord e) => e -> CountM e s ()
throwErrM = tell . countErr

runCountM :: CountM e r a -> r -> IO (a, ErrCounts e)
runCountM (CountM m) = runWriterT . runReaderT m

runCountM (CountM m) r = runWriterT (runReaderT m r)
5 changes: 3 additions & 2 deletions minipat-midi/src/Minipat/Midi/Impl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import Minipat.Live.Core (St, logAsyncState, stBackend, useCallback)
import Minipat.Live.Logger (logInfo)
import Minipat.Live.Resources (acquireAwait, qhHeap)
import Minipat.Midi.Convert (convertMidiAttrs)
import Minipat.Midi.Midi (MidiState, SortedMsg (..), TimedMsg (..))
import Minipat.Time (Arc (..))
import Nanotime (PosixTime, TimeDelta, threadDelayDelta)
import Minipat.Midi.Midi (SortedMsg (..), TimedMsg (..), PortState)

-- import Sound.RtMidi (OutputDevice)
-- import Sound.RtMidi qualified as R

Expand Down Expand Up @@ -65,7 +66,7 @@ mkTimedMsgs (WithPlayMeta pm cd) =
Nothing -> s1

data MidiData = MidiData
{ mdPortState :: !PortState
{ mdMidiState :: !MidiState
, mdObsTask :: !(Async ())
, mdSendTask :: !(Async ())
}
Expand Down
Loading

0 comments on commit 78398e2

Please sign in to comment.