Skip to content

Commit 21a29bc

Browse files
committed
Replace alsa-javacpp with alsa-panama and eliminate use of javacpp.
1 parent 9b7db21 commit 21a29bc

File tree

12 files changed

+281
-280
lines changed

12 files changed

+281
-280
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ktor-io = "3.3.3"
2525
mpfilepicker = "3.1.0"
2626
gradle-javacpp = "1.5.10"
2727

28-
alsa-javacpp = "0.1.0"
28+
alsa-panama = "0.1.0"
2929
rtmidi-javacpp = "0.1.5"
3030
libremidi-panama = "0.3.0"
3131

@@ -40,7 +40,7 @@ androidx-test-junit = { group = "androidx.test.ext", name = "junit", version.ref
4040
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidx-espresso-core" }
4141
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
4242

43-
alsa-javacpp = { module = "dev.atsushieno:alsa-javacpp", version.ref = "alsa-javacpp" }
43+
alsa-panama = { module = "dev.atsushieno:alsa-panama", version.ref = "alsa-panama" }
4444
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter-api" }
4545
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter-api" }
4646
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines-core" }

ktmidi-jvm-desktop/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ kotlin {
2222
val commonMain by getting {
2323
dependencies {
2424
implementation(project(":ktmidi"))
25-
implementation(libs.alsa.javacpp)
26-
api(libs.rtmidi.javacpp)
25+
implementation(libs.alsa.panama)
2726
implementation(libs.libremidi.panama)
2827

2928
implementation(libs.kotlinx.coroutines.core)
Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,99 @@
11
@file:Suppress("unused")
22

3-
package dev.atsushieno.alsakt
4-
5-
import dev.atsushieno.alsa.javacpp.global.Alsa
6-
import dev.atsushieno.alsa.javacpp.snd_seq_client_info_t
7-
import org.bytedeco.javacpp.BytePointer
3+
import dev.atsushieno.alsakt.AlsaVersion
4+
import dev.atsushieno.panama.alsa.alsa_global_h
5+
import dev.atsushieno.panama.alsa.alsa_seq_h
6+
import dev.atsushieno.panama.alsa.alsa_seq_midi_event_h
7+
import java.lang.foreign.Arena
8+
import java.lang.foreign.MemorySegment
89

910
class AlsaClientInfo : AutoCloseable {
1011
companion object {
11-
private fun malloc(): snd_seq_client_info_t? {
12-
val outHandle = snd_seq_client_info_t()
13-
Alsa.snd_seq_client_info_malloc(outHandle)
12+
private fun malloc(): MemorySegment {
13+
val outHandle = Arena.ofShared().allocate(alsa_seq_h.snd_seq_client_info_sizeof())
14+
alsa_seq_h.snd_seq_client_info_malloc(outHandle)
1415
return outHandle
1516
}
1617

17-
private fun free(handle: snd_seq_client_info_t?) {
18+
private fun free(handle: MemorySegment?) {
1819
if (handle != null)
19-
Alsa.snd_seq_client_info_free(handle)
20+
alsa_seq_h.snd_seq_client_info_free(handle)
2021
}
2122

2223
}
2324

2425
constructor () : this (malloc (), { handle -> free(handle) })
2526

26-
constructor (handle: snd_seq_client_info_t?, free: (snd_seq_client_info_t?) -> Unit) {
27+
constructor (handle: MemorySegment?, free: (MemorySegment?) -> Unit) {
2728
this.handle = handle
2829
this.freeFunc = free
2930
}
3031

31-
internal var handle: snd_seq_client_info_t?//Pointer<snd_seq_client_info_t>
32-
private val freeFunc: (snd_seq_client_info_t?) -> Unit
32+
internal var handle: MemorySegment?//Pointer<snd_seq_client_info_t>
33+
private val freeFunc: (MemorySegment?) -> Unit
3334

3435
override fun close () {
35-
namePtr?.deallocate()
36-
namePtr = null
3736
if (handle != null) {
3837
freeFunc(handle)
3938
handle = null
4039
}
4140
}
4241

4342
var client: Int
44-
get() = Alsa.snd_seq_client_info_get_client (handle)
45-
set(value) = Alsa.snd_seq_client_info_set_client (handle, value)
43+
get() = alsa_seq_h.snd_seq_client_info_get_client (handle)
44+
set(value) = alsa_seq_h.snd_seq_client_info_set_client (handle, value)
4645

4746
val clientType: Int
48-
get () = Alsa.snd_seq_client_info_get_type (handle)
47+
get () = alsa_seq_h.snd_seq_client_info_get_type (handle)
4948

50-
private var namePtr: BytePointer? = null
49+
private var namePtr = Arena.ofShared().allocate(256)
5150
var name: String
52-
get() = Alsa.snd_seq_client_info_get_name (handle).string
51+
get() = alsa_seq_h.snd_seq_client_info_get_name (handle).getString(0)
5352
set(value) {
54-
namePtr?.deallocate()
55-
namePtr = BytePointer(value)
56-
Alsa.snd_seq_client_info_set_name(handle, namePtr)
53+
namePtr.setString(0, value)
54+
alsa_seq_h.snd_seq_client_info_set_name(handle, namePtr)
5755
}
5856

5957
var broadcastFilter: Int
60-
get() = Alsa.snd_seq_client_info_get_broadcast_filter (handle)
61-
set(value) = Alsa.snd_seq_client_info_set_broadcast_filter (handle, value)
58+
get() = alsa_seq_h.snd_seq_client_info_get_broadcast_filter (handle)
59+
set(value) = alsa_seq_h.snd_seq_client_info_set_broadcast_filter (handle, value)
6260

6361
var errorBounce: Int
64-
get() = Alsa.snd_seq_client_info_get_error_bounce (handle)
65-
set(value) = Alsa.snd_seq_client_info_set_error_bounce (handle, value)
62+
get() = alsa_seq_h.snd_seq_client_info_get_error_bounce (handle)
63+
set(value) = alsa_seq_h.snd_seq_client_info_set_error_bounce (handle, value)
6664

6765
val card : Int
68-
get() = Alsa.snd_seq_client_info_get_card (handle)
66+
get() = alsa_seq_h.snd_seq_client_info_get_card (handle)
6967
val pid :Int
70-
get() = Alsa.snd_seq_client_info_get_pid (handle)
68+
get() = alsa_seq_h.snd_seq_client_info_get_pid (handle)
7169
val portCount: Int
72-
get() = Alsa.snd_seq_client_info_get_num_ports (handle)
70+
get() = alsa_seq_h.snd_seq_client_info_get_num_ports (handle)
7371
val eventLostCount : Int
74-
get() = Alsa.snd_seq_client_info_get_event_lost (handle)
72+
get() = alsa_seq_h.snd_seq_client_info_get_event_lost (handle)
7573

7674
private val midiVersionAvailable =
7775
AlsaVersion.major >=1 &&
7876
AlsaVersion.minor >=2 &&
7977
AlsaVersion.revision >= 10
8078
var midiVersion : Int
81-
get() = if (midiVersionAvailable) Alsa.snd_seq_client_info_get_midi_version(handle) else 0
79+
get() = if (midiVersionAvailable) alsa_seq_h.snd_seq_client_info_get_midi_version(handle) else 0
8280
set(value) {
8381
if (midiVersionAvailable)
84-
Alsa.snd_seq_client_info_set_midi_version(handle, value)
82+
alsa_seq_h.snd_seq_client_info_set_midi_version(handle, value)
8583
}
8684

8785
val umpConversion : Int
88-
get() = Alsa.snd_seq_client_info_get_ump_conversion(handle)
86+
get() = alsa_seq_h.snd_seq_client_info_get_ump_conversion(handle)
8987

9088
var isUmpGrouplessEnabled : Boolean
91-
get() = Alsa.snd_seq_client_info_get_ump_groupless_enabled(handle) != 0
92-
set(value) = Alsa.snd_seq_client_info_set_ump_groupless_enabled(handle, if (value) 1 else 0)
93-
94-
fun clearEventFilter () = Alsa.snd_seq_client_info_event_filter_clear (handle)
95-
fun addEventFilter ( eventType: Int) = Alsa.snd_seq_client_info_event_filter_add (handle, eventType)
96-
fun deleteEventFilter ( eventType: Int) = Alsa.snd_seq_client_info_event_filter_del (handle, eventType)
97-
fun isEventFiltered ( eventType: Int) = Alsa.snd_seq_client_info_event_filter_check (handle, eventType) > 0
98-
fun isUmpGroupEnabled(group: Int) = Alsa.snd_seq_client_info_get_ump_group_enabled(handle, group) != 0
99-
fun setUmpGroupEnabled(group: Int, enabled: Boolean) = Alsa.snd_seq_client_info_set_ump_group_enabled(handle, group, if (enabled) 1 else 0)
89+
get() = alsa_seq_h.snd_seq_client_info_get_ump_groupless_enabled(handle) != 0
90+
set(value) = alsa_seq_h.snd_seq_client_info_set_ump_groupless_enabled(handle, if (value) 1 else 0)
91+
92+
fun clearEventFilter () = alsa_seq_h.snd_seq_client_info_event_filter_clear (handle)
93+
fun addEventFilter ( eventType: Int) = alsa_seq_h.snd_seq_client_info_event_filter_add (handle, eventType)
94+
fun deleteEventFilter ( eventType: Int) = alsa_seq_h.snd_seq_client_info_event_filter_del (handle, eventType)
95+
fun isEventFiltered ( eventType: Int) = alsa_seq_h.snd_seq_client_info_event_filter_check (handle, eventType) > 0
96+
fun isUmpGroupEnabled(group: Int) = alsa_seq_h.snd_seq_client_info_get_ump_group_enabled(handle, group) != 0
97+
fun setUmpGroupEnabled(group: Int, enabled: Boolean) = alsa_seq_h.snd_seq_client_info_set_ump_group_enabled(handle, group, if (enabled) 1 else 0)
10098
}
10199

ktmidi-jvm-desktop/src/jvmMain/kotlin/dev/atsushieno/alsakt/AlsaException.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package dev.atsushieno.alsakt
22

3-
import dev.atsushieno.alsa.javacpp.global.Alsa
3+
import dev.atsushieno.panama.alsa.alsa_global_h
44

55
class AlsaException : Exception {
66
constructor() : super("ALSA error")
7-
constructor(errorCode: Int) : super("ALSA error: ${Alsa.snd_strerror(errorCode).string} (error code $errorCode)")
7+
constructor(errorCode: Int) : super("ALSA error: ${alsa_global_h.snd_strerror(errorCode)} (error code $errorCode)")
88
constructor(msg: String?) : super(msg)
99

1010
constructor(msg: String?, innerException: Exception?) : super(msg, innerException)
Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,112 @@
11
@file:Suppress("unused")
22

33
package dev.atsushieno.alsakt
4-
import dev.atsushieno.alsa.javacpp.global.Alsa
5-
import dev.atsushieno.alsa.javacpp.snd_seq_port_info_t
6-
import org.bytedeco.javacpp.BytePointer
4+
import dev.atsushieno.panama.alsa.alsa_global_h
5+
import dev.atsushieno.panama.alsa.alsa_seq_h
6+
import java.lang.foreign.Arena
7+
import java.lang.foreign.MemorySegment
78

89
class AlsaPortInfo : AutoCloseable {
910
companion object {
1011
const val PortSystemTimer = 0
1112
const val PortSystemAnnouncement = 1
1213

13-
private fun malloc(): snd_seq_port_info_t? {
14-
val outHandle = snd_seq_port_info_t()
15-
Alsa.snd_seq_port_info_malloc(outHandle)
14+
private fun malloc(): MemorySegment {
15+
val outHandle = Arena.ofShared().allocate(alsa_seq_h.snd_seq_port_info_sizeof())
16+
alsa_seq_h.snd_seq_port_info_malloc(outHandle)
1617
return outHandle
1718
}
1819

19-
private fun free(handle: snd_seq_port_info_t?) {
20+
private fun free(handle: MemorySegment?) {
2021
if (handle != null)
21-
Alsa.snd_seq_port_info_free(handle)
22+
alsa_seq_h.snd_seq_port_info_free(handle)
2223
}
2324
}
2425

2526
constructor () : this(malloc(), { handle -> free(handle) })
2627

27-
constructor (handle: snd_seq_port_info_t?, port: Int) {
28+
constructor (handle: MemorySegment?, port: Int) {
2829
this.handle = handle
2930
this.freeFunc = {}
3031
}
3132

32-
constructor (handle: snd_seq_port_info_t?, free: (snd_seq_port_info_t?) -> Unit) {
33+
constructor (handle: MemorySegment?, free: (MemorySegment?) -> Unit) {
3334
this.handle = handle
3435
this.freeFunc = free
3536
}
3637

37-
internal var handle: snd_seq_port_info_t?//Pointer<snd_seq_port_info_t>
38-
private val freeFunc: (snd_seq_port_info_t?) -> Unit
38+
internal var handle: MemorySegment?//Pointer<snd_seq_port_info_t>
39+
private val freeFunc: (MemorySegment?) -> Unit
3940

4041
override fun close() {
41-
namePtr?.deallocate()
42-
namePtr = null
4342
if (handle != null)
4443
freeFunc(handle)
4544
handle = null
4645
}
4746

4847
fun clone(): AlsaPortInfo {
4948
val ret = AlsaPortInfo()
50-
Alsa.snd_seq_port_info_copy(ret.handle, handle)
49+
alsa_seq_h.snd_seq_port_info_copy(ret.handle, handle)
5150
return ret
5251
}
5352

5453
var client: Int
55-
get() = Alsa.snd_seq_port_info_get_client(handle)
56-
set(value) = Alsa.snd_seq_port_info_set_client(handle, value)
54+
get() = alsa_seq_h.snd_seq_port_info_get_client(handle)
55+
set(value) = alsa_seq_h.snd_seq_port_info_set_client(handle, value)
5756

5857
var port: Int
59-
get() = Alsa.snd_seq_port_info_get_port(handle)
60-
set(value) = Alsa.snd_seq_port_info_set_port(handle, value)
58+
get() = alsa_seq_h.snd_seq_port_info_get_port(handle)
59+
set(value) = alsa_seq_h.snd_seq_port_info_set_port(handle, value)
6160

62-
private var namePtr: BytePointer? = null
61+
private var namePtr = Arena.ofShared().allocate(256)
6362
var name: String
64-
get() = Alsa.snd_seq_port_info_get_name(handle).string
63+
get() = alsa_seq_h.snd_seq_port_info_get_name(handle).getString(0)
6564
set(value) {
66-
namePtr?.deallocate()
67-
namePtr = BytePointer(value)
68-
Alsa.snd_seq_port_info_set_name(handle, namePtr)
65+
namePtr.setString(0, value)
66+
alsa_seq_h.snd_seq_port_info_set_name(handle, namePtr)
6967
}
7068

7169
var capabilities: Int
72-
get() = Alsa.snd_seq_port_info_get_capability (handle)
73-
set(value) = Alsa.snd_seq_port_info_set_capability(handle, value)
70+
get() = alsa_seq_h.snd_seq_port_info_get_capability (handle)
71+
set(value) = alsa_seq_h.snd_seq_port_info_set_capability(handle, value)
7472

7573
var portType: Int
76-
get() = Alsa.snd_seq_port_info_get_type (handle)
77-
set(value) = Alsa.snd_seq_port_info_set_type(handle, value)
74+
get() = alsa_seq_h.snd_seq_port_info_get_type (handle)
75+
set(value) = alsa_seq_h.snd_seq_port_info_set_type(handle, value)
7876

7977
var midiChannels: Int
80-
get() = Alsa.snd_seq_port_info_get_midi_channels(handle)
81-
set(value) = Alsa.snd_seq_port_info_set_midi_channels(handle, value)
78+
get() = alsa_seq_h.snd_seq_port_info_get_midi_channels(handle)
79+
set(value) = alsa_seq_h.snd_seq_port_info_set_midi_channels(handle, value)
8280

8381
var midiVoices: Int
84-
get() = Alsa.snd_seq_port_info_get_midi_voices(handle)
85-
set(value) = Alsa.snd_seq_port_info_set_midi_voices(handle, value)
82+
get() = alsa_seq_h.snd_seq_port_info_get_midi_voices(handle)
83+
set(value) = alsa_seq_h.snd_seq_port_info_set_midi_voices(handle, value)
8684

8785
var synthVoices: Int
88-
get() = Alsa.snd_seq_port_info_get_synth_voices(handle)
89-
set(value) = Alsa.snd_seq_port_info_set_synth_voices(handle, value)
86+
get() = alsa_seq_h.snd_seq_port_info_get_synth_voices(handle)
87+
set(value) = alsa_seq_h.snd_seq_port_info_set_synth_voices(handle, value)
9088

9189
val readSubscriptions
92-
get() = Alsa.snd_seq_port_info_get_read_use(handle)
90+
get() = alsa_seq_h.snd_seq_port_info_get_read_use(handle)
9391

9492
val writeSubscriptions
95-
get() = Alsa.snd_seq_port_info_get_write_use(handle)
93+
get() = alsa_seq_h.snd_seq_port_info_get_write_use(handle)
9694

9795
var portSpecified
98-
get() = Alsa.snd_seq_port_info_get_port_specified(handle) > 0
99-
set(value) = Alsa.snd_seq_port_info_set_port_specified(handle, if (value) 1 else 0)
96+
get() = alsa_seq_h.snd_seq_port_info_get_port_specified(handle) > 0
97+
set(value) = alsa_seq_h.snd_seq_port_info_set_port_specified(handle, if (value) 1 else 0)
10098

10199
var timestampQueue: Int
102-
get() = Alsa.snd_seq_port_info_get_timestamp_queue(handle)
103-
set(value) = Alsa.snd_seq_port_info_set_timestamp_queue(handle, value)
100+
get() = alsa_seq_h.snd_seq_port_info_get_timestamp_queue(handle)
101+
set(value) = alsa_seq_h.snd_seq_port_info_set_timestamp_queue(handle, value)
104102

105103
var timestampReal: Int
106-
get() = Alsa.snd_seq_port_info_get_timestamp_real(handle)
107-
set(value) = Alsa.snd_seq_port_info_set_timestamp_real(handle, value)
104+
get() = alsa_seq_h.snd_seq_port_info_get_timestamp_real(handle)
105+
set(value) = alsa_seq_h.snd_seq_port_info_set_timestamp_real(handle, value)
108106

109107
var timestamping: Boolean
110-
get() = Alsa.snd_seq_port_info_get_timestamping(handle) != 0
111-
set(value) = Alsa.snd_seq_port_info_set_timestamping(handle, if (value) 1 else 0)
108+
get() = alsa_seq_h.snd_seq_port_info_get_timestamping(handle) != 0
109+
set(value) = alsa_seq_h.snd_seq_port_info_set_timestamping(handle, if (value) 1 else 0)
112110

113111
val id: String
114112
get() = "${client}_${port}"
@@ -118,10 +116,10 @@ class AlsaPortInfo : AutoCloseable {
118116
val version = "" // FIXME: implement
119117

120118
var direction: Int
121-
get() = Alsa.snd_seq_port_info_get_direction(handle)
122-
set(value) = Alsa.snd_seq_port_info_set_direction(handle, value)
119+
get() = alsa_seq_h.snd_seq_port_info_get_direction(handle)
120+
set(value) = alsa_seq_h.snd_seq_port_info_set_direction(handle, value)
123121

124122
var umpGroup: Int
125-
get() = Alsa.snd_seq_port_info_get_ump_group(handle)
126-
set(value) = Alsa.snd_seq_port_info_set_ump_group(handle, value)
123+
get() = alsa_seq_h.snd_seq_port_info_get_ump_group(handle)
124+
set(value) = alsa_seq_h.snd_seq_port_info_set_ump_group(handle, value)
127125
}

0 commit comments

Comments
 (0)