feat: wrap metadata API and add one usage example
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
		
							parent
							
								
									31b83223fc
								
							
						
					
					
						commit
						34d3093505
					
				
							
								
								
									
										46
									
								
								examples/jacket_list_all_properties.nim
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								examples/jacket_list_all_properties.nim
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
			
		||||
import std/[logging, strformat]
 | 
			
		||||
import jacket
 | 
			
		||||
 | 
			
		||||
var
 | 
			
		||||
    jclient: ClientP
 | 
			
		||||
    status: cint
 | 
			
		||||
    descs: ptr UncheckedArray[Description]
 | 
			
		||||
 | 
			
		||||
var log = newConsoleLogger(when defined(release): lvlInfo else: lvlDebug)
 | 
			
		||||
 | 
			
		||||
proc errorCb(msg: cstring) {.cdecl.} =
 | 
			
		||||
    # Suppress verbose JACK error messages when server is not available by 
 | 
			
		||||
    # default. Pass ``lvlAll`` when creating the logger to enable them.
 | 
			
		||||
    debug "JACK error: " & $msg
 | 
			
		||||
 | 
			
		||||
addHandler(log)
 | 
			
		||||
setErrorFunction(errorCb)
 | 
			
		||||
jclient = clientOpen("jacket_property", NullOption.ord, status.addr)
 | 
			
		||||
debug "JACK server status: " & $status
 | 
			
		||||
 | 
			
		||||
if jclient == nil:
 | 
			
		||||
    error getJackStatusErrorString(status)
 | 
			
		||||
    quit 1
 | 
			
		||||
 | 
			
		||||
let numDescs = getAllProperties(descs)
 | 
			
		||||
 | 
			
		||||
if numDescs != -1:
 | 
			
		||||
    var desc: Description
 | 
			
		||||
 | 
			
		||||
    for i in 0..<numDescs:
 | 
			
		||||
        desc = descs[i]
 | 
			
		||||
        echo fmt"Subject: {desc.subject}"
 | 
			
		||||
 | 
			
		||||
        if desc.property_cnt > 0:
 | 
			
		||||
            for p in 0..<desc.property_cnt:
 | 
			
		||||
                var prop = desc.properties[p]
 | 
			
		||||
                echo fmt"* {prop.key}: {prop.data} (type: {prop.type})"
 | 
			
		||||
 | 
			
		||||
        echo ""
 | 
			
		||||
        freeDescription(desc.addr, 0)
 | 
			
		||||
 | 
			
		||||
    free(descs)
 | 
			
		||||
else:
 | 
			
		||||
    error "Could not get properties!"
 | 
			
		||||
 | 
			
		||||
discard jclient.clientClose
 | 
			
		||||
@ -167,6 +167,27 @@ const
 | 
			
		||||
    EXTENDED_TIME_INFO* = true
 | 
			
		||||
    JACK_TICK_DOUBLE* = true
 | 
			
		||||
 | 
			
		||||
# Metadata
 | 
			
		||||
 | 
			
		||||
type
 | 
			
		||||
    Property* = object
 | 
			
		||||
        key*: cstring
 | 
			
		||||
        data*: cstring
 | 
			
		||||
        `type`*: cstring
 | 
			
		||||
 | 
			
		||||
    PropertyChange* {.size: sizeof(cint).} = enum
 | 
			
		||||
        PropertyCreated,
 | 
			
		||||
        PropertyChanged,
 | 
			
		||||
        PropertyDeleted
 | 
			
		||||
 | 
			
		||||
    Description* = object
 | 
			
		||||
        subject*: Uuid
 | 
			
		||||
        property_cnt*: uint32
 | 
			
		||||
        properties*: ptr UncheckedArray[Property]
 | 
			
		||||
        property_size*: uint32
 | 
			
		||||
 | 
			
		||||
    DescriptionP* = ptr Description
 | 
			
		||||
 | 
			
		||||
# Callback function types
 | 
			
		||||
 | 
			
		||||
type
 | 
			
		||||
@ -192,6 +213,11 @@ type
 | 
			
		||||
    JackTimebaseCallback* = proc (state: TransportState; nframes: NFrames; pos: ptr Position; newPos: cint;
 | 
			
		||||
                                  arg: pointer) {.cdecl.}
 | 
			
		||||
 | 
			
		||||
    JackPropertyChangeCallback* = proc (subject: Uuid, key: cstring, change: JackPropertyChange, arg: pointer) {.cdecl.}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    PropertyChangeCallback* = proc (subject: Uuid, key: cstring, change: PropertyChange, arg: pointer) {.cdecl.}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# ----------------------------- Version info ------------------------------
 | 
			
		||||
 | 
			
		||||
@ -603,6 +629,37 @@ void jack_get_transport_info (jack_client_t *client, jack_transport_info_t *tinf
 | 
			
		||||
void jack_set_transport_info (jack_client_t *client, jack_transport_info_t *tinfo)
 | 
			
		||||
]#
 | 
			
		||||
 | 
			
		||||
# ------------------------------- Metadata --------------------------------
 | 
			
		||||
 | 
			
		||||
# int jack_set_property (jack_client_t*, jack_uuid_t subject, const char* key, const char* value, const char* type)
 | 
			
		||||
proc setProperty*(client: ClientP, subject: Uuid, key, value, `type`: cstring): cint {.importc: "jack_set_property".}
 | 
			
		||||
 | 
			
		||||
# int jack_get_property (jack_uuid_t subject, const char* key, char** value, char** type)
 | 
			
		||||
proc getProperty*(subject: Uuid, key: cstring, value, `type`: ptr cstring): cint {.importc: "jack_get_property".}
 | 
			
		||||
 | 
			
		||||
# void jack_free_description (jack_description_t* desc, int free_description_itself)
 | 
			
		||||
proc freeDescription*(desc: DescriptionP, freeDescriptionItself: cint) {.importc: "jack_free_description".}
 | 
			
		||||
 | 
			
		||||
# int jack_get_properties (jack_uuid_t subject, jack_description_t* desc)
 | 
			
		||||
proc getProperties*(subject: Uuid, desc: DescriptionP): cint {.importc: "jack_get_properties".}
 | 
			
		||||
 | 
			
		||||
# int jack_get_all_properties (jack_description_t** descs)
 | 
			
		||||
proc getAllProperties*(descs: var ptr UncheckedArray[Description]): cint {.importc: "jack_get_all_properties".}
 | 
			
		||||
 | 
			
		||||
# int jack_remove_property (jack_client_t* client, jack_uuid_t subject, const char* key)
 | 
			
		||||
proc removeProperty*(client: ClientP, subject: Uuid): cint {.importc: "jack_remove_property".}
 | 
			
		||||
 | 
			
		||||
# int jack_remove_properties (jack_client_t* client, jack_uuid_t subject)
 | 
			
		||||
proc removeProperties*(client: ClientP, subject: Uuid): cint {.importc: "jack_remove_properties".}
 | 
			
		||||
 | 
			
		||||
# int jack_remove_all_properties (jack_client_t* client)
 | 
			
		||||
proc removeAllProperties*(client: ClientP): cint {.importc: "jack_remove_all_properties".}
 | 
			
		||||
 | 
			
		||||
# int jack_set_property_change_callback (jack_client_t* client, JackPropertyChangeCallback callback, void* arg)
 | 
			
		||||
proc setPropertyChangeCallback*(client: ClientP, callback: PropertyChangeCallback, arg: pointer): cint {.
 | 
			
		||||
    importc: "jack_set_property_change_callback".}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# ---------------------------- Error handling -----------------------------
 | 
			
		||||
 | 
			
		||||
proc setErrorFunction*(errorCallback: JackErrorCallback) {.importc: "jack_set_error_function".}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user