Skip to content

Commit ed3ce80

Browse files
committed
improve generator
1 parent a7f7bd7 commit ed3ce80

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ authors = ["SteffenPL <[email protected]> and contributors"]
44
version = "0.1.0"
55

66
[deps]
7-
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
87
PortMidi_jll = "6b227df9-c220-5195-838c-e1464939a66f"
98

109
[compat]
1110
PortMidi_jll = "2.0.4"
1211
julia = "1.6"
13-
CEnum = "0.5"
1412

1513
[extras]
1614
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

gen/generator.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ output_file_path = "../src/PortMidi.jl"
44
module_name = "PortMidi"
55
jll_pkg_name = "PortMidi_jll"
66

7-
# use_julia_native_enum_type = true
7+
use_julia_native_enum_type = true
88

9-
# prologue_file_path = "prologue.jl"
10-
# epilogue_file_path = "epilogue.jl"
9+
prologue_file_path = "prologue.jl"
10+
epilogue_file_path = "epilogue.jl"
1111

12-
# export_symbol_prefixes = ["Pm"]
13-
# output_ignorelist = ["TRUE", "FALSE"]
14-
15-
ignore_pure_definition = false
12+
export_symbol_prefixes = ["Pm"]
13+
output_ignorelist = ["TRUE", "FALSE"]

src/PortMidi.jl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module PortMidi
33
using PortMidi_jll
44
export PortMidi_jll
55

6-
using CEnum
6+
to_c_type(::Type{<:AbstractString}) = Cstring # or Ptr{Cchar}
7+
to_c_type(t::Type{<:Union{AbstractArray,Ref}}) = Ptr{eltype(t)}
78

89
const PmQueue = Cvoid
910

@@ -21,9 +22,9 @@ end
2122

2223
const PortMidiStream = Cvoid
2324

24-
@cenum PmError::Int32 begin
25+
@enum PmError::Int32 begin
2526
pmNoError = 0
26-
pmNoData = 0
27+
# pmNoData = 0
2728
pmGotData = 1
2829
pmHostError = -10000
2930
pmInvalidDeviceId = -9999
@@ -163,7 +164,7 @@ function Pm_WriteSysEx(stream, when, msg)
163164
ccall((:Pm_WriteSysEx, libportmidi), PmError, (Ptr{PortMidiStream}, PmTimestamp, Ptr{Cuchar}), stream, when, msg)
164165
end
165166

166-
@cenum PtError::Int32 begin
167+
@enum PtError::Int32 begin
167168
ptNoError = 0
168169
ptHostError = -10000
169170
ptAlreadyStarted = -9999
@@ -196,10 +197,6 @@ function Pt_Sleep(duration)
196197
ccall((:Pt_Sleep, libportmidi), Cvoid, (int32_t,), duration)
197198
end
198199

199-
const FALSE = 0
200-
201-
const TRUE = 1
202-
203200
const PM_DEFAULT_SYSEX_BUFFER_SIZE = 1024
204201

205202
const PmStream = PortMidiStream
@@ -252,4 +249,19 @@ const PM_FILT_TUNE = 1 << 0x06
252249

253250
const PM_FILT_SYSTEMCOMMON = ((PM_FILT_MTC | PM_FILT_SONG_POSITION) | PM_FILT_SONG_SELECT) | PM_FILT_TUNE
254251

252+
Pm_Message(status, data1, data2) = ((((data2) << 16) & 0xFF0000) | (((data1) << 8) & 0xFF00) | ((status) & 0xFF))
253+
Pm_MessageStatus(msg) = ((msg) & 0xFF)
254+
Pm_MessageData1(msg) = (((msg) >> 8) & 0xFF)
255+
Pm_MessageData2(msg) = (((msg) >> 16) & 0xFF)
256+
257+
export Pm_Message, Pm_MessageStatus, Pm_MessageData1, Pm_MessageData2
258+
259+
# exports
260+
const PREFIXES = ["Pm"]
261+
for name in names(@__MODULE__; all=true), prefix in PREFIXES
262+
if startswith(string(name), prefix)
263+
@eval export $name
264+
end
265+
end
266+
255267
end # module

0 commit comments

Comments
 (0)