11@file:Suppress(" unused" )
22
33package 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
89class 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