Skip to content

Commit

Permalink
improve generator
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenPL committed Jan 13, 2024
1 parent a7f7bd7 commit ed3ce80
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ authors = ["SteffenPL <[email protected]> and contributors"]
version = "0.1.0"

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

[compat]
PortMidi_jll = "2.0.4"
julia = "1.6"
CEnum = "0.5"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
12 changes: 5 additions & 7 deletions gen/generator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ output_file_path = "../src/PortMidi.jl"
module_name = "PortMidi"
jll_pkg_name = "PortMidi_jll"

# use_julia_native_enum_type = true
use_julia_native_enum_type = true

# prologue_file_path = "prologue.jl"
# epilogue_file_path = "epilogue.jl"
prologue_file_path = "prologue.jl"
epilogue_file_path = "epilogue.jl"

# export_symbol_prefixes = ["Pm"]
# output_ignorelist = ["TRUE", "FALSE"]

ignore_pure_definition = false
export_symbol_prefixes = ["Pm"]
output_ignorelist = ["TRUE", "FALSE"]
28 changes: 20 additions & 8 deletions src/PortMidi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module PortMidi
using PortMidi_jll
export PortMidi_jll

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

const PmQueue = Cvoid

Expand All @@ -21,9 +22,9 @@ end

const PortMidiStream = Cvoid

@cenum PmError::Int32 begin
@enum PmError::Int32 begin
pmNoError = 0
pmNoData = 0
# pmNoData = 0
pmGotData = 1
pmHostError = -10000
pmInvalidDeviceId = -9999
Expand Down Expand Up @@ -163,7 +164,7 @@ function Pm_WriteSysEx(stream, when, msg)
ccall((:Pm_WriteSysEx, libportmidi), PmError, (Ptr{PortMidiStream}, PmTimestamp, Ptr{Cuchar}), stream, when, msg)
end

@cenum PtError::Int32 begin
@enum PtError::Int32 begin
ptNoError = 0
ptHostError = -10000
ptAlreadyStarted = -9999
Expand Down Expand Up @@ -196,10 +197,6 @@ function Pt_Sleep(duration)
ccall((:Pt_Sleep, libportmidi), Cvoid, (int32_t,), duration)
end

const FALSE = 0

const TRUE = 1

const PM_DEFAULT_SYSEX_BUFFER_SIZE = 1024

const PmStream = PortMidiStream
Expand Down Expand Up @@ -252,4 +249,19 @@ const PM_FILT_TUNE = 1 << 0x06

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

Pm_Message(status, data1, data2) = ((((data2) << 16) & 0xFF0000) | (((data1) << 8) & 0xFF00) | ((status) & 0xFF))
Pm_MessageStatus(msg) = ((msg) & 0xFF)
Pm_MessageData1(msg) = (((msg) >> 8) & 0xFF)
Pm_MessageData2(msg) = (((msg) >> 16) & 0xFF)

export Pm_Message, Pm_MessageStatus, Pm_MessageData1, Pm_MessageData2

# exports
const PREFIXES = ["Pm"]
for name in names(@__MODULE__; all=true), prefix in PREFIXES
if startswith(string(name), prefix)
@eval export $name
end
end

end # module

2 comments on commit ed3ce80

@SteffenPL
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes: A wrapper for the C library PortMidi.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/98826

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" ed3ce80d4f330b09fb70ad555dbc72d6c1e549ef
git push origin v0.1.0

Please sign in to comment.