Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit ce5bdce

Browse files
committed
Remove Cabal warnings
1 parent a9c6d3f commit ce5bdce

File tree

4 files changed

+49
-34
lines changed

4 files changed

+49
-34
lines changed

tidal-parse-ffi/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for tidal-listener
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.

tidal-parse-ffi/src/Sound/Tidal/Parse/FFI.hs

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE ForeignFunctionInterface #-}
3+
{-# LANGUAGE DeriveGeneric #-}
4+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
35

46
module Sound.Tidal.Parse.FFI where
57

@@ -10,39 +12,47 @@ import qualified Data.ByteString.Lazy.Char8 as B
1012
import qualified Data.Map.Strict as Map
1113
import Data.Maybe (fromMaybe)
1214
import Text.Read (readMaybe)
13-
import Data.Ratio ((%))
15+
import GHC.Generics (Generic)
1416

1517
import Sound.Tidal.Parse (parseTidal)
16-
import Sound.Tidal.Context
17-
import Sound.Tidal.Pattern (Value)
18-
import Sound.Tidal.Show (show)
19-
20-
-- Ensure Tidal's `Value` is converted to JSON properly
21-
instance ToJSON Value where
22-
toJSON (VS s) = toJSON s
23-
toJSON (VI i) = toJSON i
24-
toJSON (VF f) = toJSON f
25-
toJSON (VN n) = toJSON $ show n
26-
toJSON (VR r) = toJSON $ show r
27-
toJSON (VB b) = toJSON b
28-
toJSON (VX xs) = toJSON xs
29-
toJSON (VPattern pat) = toJSON $ show pat
30-
toJSON (VState f) = toJSON $ show $ f Map.empty
31-
toJSON (VList vs) = toJSON vs
32-
33-
-- JSON serialization for ArcF
34-
instance (Real a) => ToJSON (ArcF a) where
35-
toJSON (Arc start stop) =
36-
object ["start" .= (realToFrac start :: Double),
37-
"stop" .= (realToFrac stop :: Double)]
38-
39-
-- JSON serialization for EventF
40-
instance (ToJSON a, ToJSON b) => ToJSON (EventF a b) where
41-
toJSON (Event ctx whole part value) =
42-
object [ "whole" .= whole
43-
, "part" .= part
44-
, "value" .= value
45-
]
18+
import Sound.Tidal.Pattern
19+
import Sound.Tidal.Params ()
20+
import Sound.Tidal.Show ()
21+
22+
-- Newtype wrappers to avoid orphan instances
23+
newtype JSONValue = JSONValue { unJSONValue :: Value }
24+
deriving (Generic)
25+
26+
instance ToJSON JSONValue where
27+
toJSON (JSONValue (VS str)) = toJSON str
28+
toJSON (JSONValue (VI i)) = toJSON i
29+
toJSON (JSONValue (VF f)) = toJSON f
30+
toJSON (JSONValue (VN num)) = toJSON $ show num
31+
toJSON (JSONValue (VR r)) = toJSON $ show r
32+
toJSON (JSONValue (VB b)) = toJSON b
33+
toJSON (JSONValue (VX xs)) = toJSON xs
34+
toJSON (JSONValue (VPattern pat)) = toJSON $ show pat
35+
toJSON (JSONValue (VState f)) = toJSON $ show $ f Map.empty
36+
toJSON (JSONValue (VList vs)) = toJSON $ map JSONValue vs
37+
38+
newtype JSONArcF = JSONArcF (ArcF Rational)
39+
deriving (Generic)
40+
41+
instance ToJSON JSONArcF where
42+
toJSON (JSONArcF (Arc arcStart arcStop)) =
43+
object ["start" .= (realToFrac arcStart :: Double),
44+
"stop" .= (realToFrac arcStop :: Double)]
45+
46+
newtype JSONEventF = JSONEventF (Event (Map.Map String Value))
47+
deriving (Generic)
48+
49+
instance ToJSON JSONEventF where
50+
toJSON (JSONEventF (Event _ctx evWhole evPart evValue)) =
51+
object [ "whole" .= fmap JSONArcF evWhole -- Handle Maybe
52+
, "part" .= JSONArcF evPart
53+
, "value" .= fmap JSONValue evValue ]
54+
55+
4656

4757
-- Foreign export wrapper function
4858
foreign export ccall eval_pattern_c :: CString -> CString -> IO CString
@@ -65,7 +75,7 @@ encodeError err = Aeson.object ["error" Aeson..= err]
6575

6676
encodeSuccess :: Double -> [Event (Map.Map String Value)] -> Aeson.Value
6777
encodeSuccess arcLen events =
68-
Aeson.object ["arcLen" .= arcLen, "events" .= events]
78+
Aeson.object ["arcLen" .= arcLen, "events" .= map JSONEventF events]
6979

7080
-- Helper functions to handle parsing and querying
7181
parseAndQuery :: String -> Double -> Either String [Event (Map.Map String Value)]

tidal-parse-ffi/test/Sound/Tidal/TidalParseFFITest.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Sound.Tidal.TidalParseFFITest where
55

66
import Foreign.C.String (CString, peekCString, newCString)
77
import Test.HUnit
8-
import Data.Aeson (Value, decode, encode, object, (.=))
8+
import Data.Aeson (Value, encode, object, (.=))
99
import qualified Data.ByteString.Lazy.Char8 as B
1010

1111
-- Foreign function import

tidal-parse-ffi/tidal-parse-ffi.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: tidal-parse-ffi
22

33
license: GPL-3
44
license-file: LICENSE
5-
Extra-source-files: README.md
5+
extra-doc-files: CHANGELOG.md, README.md
66

77
version: 0.1.0
88
build-type: Simple

0 commit comments

Comments
 (0)