packages feed

RtMidi 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+59/−42 lines, 4 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Sound.RtMidi: DebugWarning :: ErrorType
+ Sound.RtMidi: DriverError :: ErrorType
+ Sound.RtMidi: Error :: ErrorType -> String -> Error
+ Sound.RtMidi: InvalidDevice :: ErrorType
+ Sound.RtMidi: InvalidParameter :: ErrorType
+ Sound.RtMidi: InvalidUse :: ErrorType
+ Sound.RtMidi: MemoryError :: ErrorType
+ Sound.RtMidi: NoDevicesFound :: ErrorType
+ Sound.RtMidi: SystemError :: ErrorType
+ Sound.RtMidi: ThreadError :: ErrorType
+ Sound.RtMidi: UnspecifiedError :: ErrorType
+ Sound.RtMidi: Warning :: ErrorType
+ Sound.RtMidi: instance Foreign.Storable.Storable Sound.RtMidi.Wrapper
+ Sound.RtMidi: instance GHC.Classes.Eq Sound.RtMidi.Wrapper
+ Sound.RtMidi: instance GHC.Show.Show Sound.RtMidi.Wrapper
+ Sound.RtMidi: ready :: Device -> IO Bool
+ Sound.RtMidi: reportError :: Device -> ErrorType -> String -> IO ()

Files

RtMidi.cabal view
@@ -1,5 +1,5 @@ name:                RtMidi-version:             0.1.0.0+version:             0.1.1.0 description:         Haskell wrapper for RtMidi, the lightweight, cross-platform MIDI I/O library. category:            Sound build-type:          Simple@@ -40,7 +40,7 @@   exposed-modules:     Sound.RtMidi   -- other-modules:          -- other-extensions:    -  build-depends:       base >=4.9 && <4.10+  build-depends:       base >=4.9 && <4.13   default-language:    Haskell2010   include-dirs:        rtmidi   extra-libraries:     stdc++
Sound/RtMidi.hs view
@@ -4,9 +4,12 @@ -- | Interface to RtMidi module Sound.RtMidi (       Device-    , Error-    , ErrorType+    , Error (..)+    , ErrorType (..)     , Api(..)+    , ready+    , reportError+--    , checkForErrors     , compiledApis     , openPort     , openVirtualPort@@ -34,16 +37,16 @@ import Foreign.C.String  -data Device = Input (Ptr ()) | Output (Ptr ())+data Device = Input (Ptr Wrapper) | Output (Ptr Wrapper) -device :: Device -> Ptr ()+device :: Device -> Ptr Wrapper device (Input x) = x device (Output x) = x -toInput :: Device -> Ptr ()+toInput :: Device -> Ptr Wrapper toInput (Input x) = x -toOutput :: Device -> Ptr ()+toOutput :: Device -> Ptr Wrapper toOutput (Output x) = x  data Api@@ -114,20 +117,34 @@ data Wrapper = Wrapper              { ptr :: Ptr ()              , ok  :: Bool-             , msg :: String-             }+             , msg :: CString+             } deriving (Show, Eq) +instance Storable Wrapper where+   sizeOf _  = 24+   alignment = sizeOf+   peek ptr  = do+      a <- peekByteOff ptr 0+      b <- peekByteOff ptr 8+      c <- peekByteOff ptr 16+      return $ Wrapper a b c -peekWrapper :: Ptr () -> IO Wrapper-peekWrapper p = do-  a <- peek (castPtr p)-  b <- peek $ castPtr (plusPtr p $ sizeOf a)-  c <- peekCString $ castPtr (plusPtr p $ sizeOf a + sizeOf b)-  return $ Wrapper a b c+-- | Check if a device is ok+ready :: Device -> IO Bool+ready d = fmap ok $ peek (device d) -checkForErrors :: Device -> IO (Maybe String)-checkForErrors d = peekWrapper (device d) >>= \w -> if ok w then return Nothing else return $ Just (msg w) +checkForErrors :: Device -> IO [Char]+checkForErrors d = peek (device d) >>= (\w -> do+    (putStrLn $ show w)+    a <- peekArray0 0 $ plusPtr (castPtr (msg w)) 10+    return a) >>= return . map castCCharToChar++reportError :: Device -> ErrorType -> String -> IO ()+reportError d et em = withCString em $ rtmidi_error (device d) (toEnum . fromEnum $ et)++foreign import ccall "rtmidi_c.h rtmidi_error"+   rtmidi_error :: Ptr Wrapper -> CInt -> CString -> IO ()   foreign import ccall "rtmidi_c.h rtmidi_sizeof_rtmidi_api"    rtmidi_sizeof_rtmidi_api :: IO CInt@@ -136,64 +153,61 @@ foreign import ccall "rtmidi_c.h rtmidi_get_compiled_api"    rtmidi_get_compiled_api :: Ptr (Ptr CInt) -> IO CInt --- foreign import ccall "rtmidi_c.h rtmidi_error"---    rtmidi_error :: CInt -> CString -> IO () - foreign import ccall "rtmidi_c.h rtmidi_open_port"-   rtmidi_open_port :: Ptr () -> CInt -> CString -> IO ()+   rtmidi_open_port :: Ptr Wrapper -> CInt -> CString -> IO ()  foreign import ccall "rtmidi_c.h rtmidi_open_virtual_port"-   rtmidi_open_virtual_port :: Ptr () -> CString -> IO ()+   rtmidi_open_virtual_port :: Ptr Wrapper -> CString -> IO ()  foreign import ccall "rtmidi_c.h rtmidi_close_port"-   rtmidi_close_port :: Ptr () -> IO ()+   rtmidi_close_port :: Ptr Wrapper -> IO ()  foreign import ccall "rtmidi_c.h rtmidi_get_port_count"-   rtmidi_get_port_count :: Ptr () -> IO CInt+   rtmidi_get_port_count :: Ptr Wrapper -> IO CInt  foreign import ccall "rtmidi_c.h rtmidi_get_port_name"-   rtmidi_get_port_name :: Ptr () -> CInt -> IO CString+   rtmidi_get_port_name :: Ptr Wrapper -> CInt -> IO CString   foreign import ccall "rtmidi_c.h rtmidi_in_create_default"-   rtmidi_in_create_default :: IO (Ptr ())+   rtmidi_in_create_default :: IO (Ptr Wrapper)  foreign import ccall "rtmidi_c.h rtmidi_in_create"-   rtmidi_in_create :: CInt -> CString -> CInt -> IO (Ptr ())+   rtmidi_in_create :: CInt -> CString -> CInt -> IO (Ptr Wrapper)  foreign import ccall "rtmidi_c.h rtmidi_in_free"-   rtmidi_in_free :: Ptr () -> IO ()+   rtmidi_in_free :: Ptr Wrapper -> IO ()  foreign import ccall "rtmidi_c.h rtmidi_in_get_current_api"-   rtmidi_in_get_current_api :: Ptr () -> IO CInt+   rtmidi_in_get_current_api :: Ptr Wrapper -> IO CInt  foreign import ccall "rtmidi_c.h rtmidi_in_set_callback"-   rtmidi_in_set_callback :: Ptr () -> FunPtr (CDouble -> Ptr CUChar -> CInt -> Ptr () -> IO ()) -> Ptr () -> IO ()+   rtmidi_in_set_callback :: Ptr Wrapper -> FunPtr (CDouble -> Ptr CUChar -> CInt -> Ptr () -> IO ()) -> Ptr () -> IO ()  foreign import ccall "rtmidi_c.h rtmidi_in_cancel_callback"-   rtmidi_in_cancel_callback :: Ptr () -> IO ()+   rtmidi_in_cancel_callback :: Ptr Wrapper -> IO ()  foreign import ccall "rtmidi_c.h rtmidi_in_ignore_types"-   rtmidi_in_ignore_types :: Ptr () -> Bool -> Bool -> Bool -> IO ()+   rtmidi_in_ignore_types :: Ptr Wrapper -> Bool -> Bool -> Bool -> IO ()  foreign import ccall "rtmidi_c.h rtmidi_in_get_message"-   rtmidi_in_get_message :: Ptr () -> Ptr (Ptr CUChar) -> Ptr CSize -> IO CDouble+   rtmidi_in_get_message :: Ptr Wrapper -> Ptr (Ptr CUChar) -> Ptr CSize -> IO CDouble  foreign import ccall "rtmidi_c.h rtmidi_out_create_default"-   rtmidi_out_create_default :: IO (Ptr ())+   rtmidi_out_create_default :: IO (Ptr Wrapper)  foreign import ccall "rtmidi_c.h rtmidi_out_create"-   rtmidi_out_create :: CInt -> CString -> IO (Ptr ())+   rtmidi_out_create :: CInt -> CString -> IO (Ptr Wrapper)  foreign import ccall "rtmidi_c.h rtmidi_out_free"-   rtmidi_out_free :: Ptr () -> IO ()+   rtmidi_out_free :: Ptr Wrapper -> IO ()  foreign import ccall "rtmidi_c.h rtmidi_out_get_current_api"-   rtmidi_out_get_current_api :: Ptr () -> IO CInt+   rtmidi_out_get_current_api :: Ptr Wrapper -> IO CInt  foreign import ccall "rtmidi_c.h rtmidi_out_send_message"-   rtmidi_out_send_message :: Ptr () -> Ptr CUChar -> CInt -> IO CInt+   rtmidi_out_send_message :: Ptr Wrapper -> Ptr CUChar -> CInt -> IO CInt   apiSize :: IO Int
rtmidi/rtmidi_c.cpp view
@@ -36,11 +36,12 @@ 	} } -void rtmidi_error (MidiApi *api, enum RtMidiErrorType type, const char* errorString)+void rtmidi_error (RtMidiPtr device, enum RtMidiErrorType type, const char* errorString) { 	std::string msg = errorString;-	api->error ((RtMidiError::Type) type, msg);+	((MidiApi*) device->ptr)->error ((RtMidiError::Type) type, msg); }+  void rtmidi_open_port (RtMidiPtr device, unsigned int portNumber, const char *portName) {
rtmidi/rtmidi_c.h view
@@ -3,6 +3,8 @@ #ifndef RTMIDI_C_H #define RTMIDI_C_H +#include <stdlib.h>+ #if defined(RTMIDI_EXPORT) #define RTMIDIAPI __declspec(dllexport) #else@@ -45,7 +47,7 @@  /* RtMidi API */ RTMIDIAPI int rtmidi_get_compiled_api (enum RtMidiApi **apis); // return length for NULL argument.-RTMIDIAPI void rtmidi_error (enum RtMidiErrorType type, const char* errorString);+RTMIDIAPI void rtmidi_error (RtMidiPtr device, enum RtMidiErrorType type, const char* errorString);  RTMIDIAPI void rtmidi_open_port (RtMidiPtr device, unsigned int portNumber, const char *portName); RTMIDIAPI void rtmidi_open_virtual_port (RtMidiPtr device, const char *portName);