Skip to content
Browse files

woo, stuff

  • Loading branch information...
0 parents commit 3d9549ca6032960256d9d257732ad5eb578c61d1 @flussence committed
Showing with 139 additions and 0 deletions.
  1. +9 −0 README.md
  2. +17 −0 bin/p6xmms2
  3. +1 −0 deps.proto
  4. +103 −0 lib/XMMS2/Client.pm6
  5. +9 −0 t/basic.t
9 README.md
@@ -0,0 +1,9 @@
+# perl6-XMMS2
+
+An XMMS2 client module for Perl 6 and a command line tool to use it with, inspired by tadzik++'s
+[perl6-MPD](//github.com/tadzik/perl6-MPD). It's actually based on the xmms2-tutorial C code.
+
+Currently it connects (in a hacky way), and that's about it. Even if it did work, only the “play”
+function is implemented anyway.
+
+You can look at the pretty code though.
17 bin/p6xmms2
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl6
+use v6;
+use XMMS2::Client;
+
+multi sub MAIN('play') {
+ client.play;
+}
+
+sub client {
+ # This is a hack because I don't know how to write "C NULL"
+ my $path = (
+ %*ENV<XMMS_PATH>,
+ "unix:///tmp/xmms-ipc-{qx[whoami].trim}"
+ ).first: *.so;
+
+ return XMMS2::Client.new(:client-name<p6xmms2>, :$path);
+}
1 deps.proto
@@ -0,0 +1 @@
+zavolaj
103 lib/XMMS2/Client.pm6
@@ -0,0 +1,103 @@
+use v6;
+use NativeCall;
+
+#####
+# Pointer to an xmms2d connection
+class xmmsc_connection_t is OpaquePointer {
+ # This doesn't seem to work. It'd be nice if it did though.
+ #submethod DESTROY { xmmsc_unref(self) }
+}
+
+# Result struct from a command
+class xmmsc_result_t is OpaquePointer {
+ #submethod DESTROY { xmmsc_result_unref(self) }
+}
+
+# XMMS2 variant value
+class xmmsv_t is OpaquePointer;
+
+#####
+# The nice part that does stuff
+class XMMS2::Client {
+ has xmmsc_connection_t $!connection;
+
+ method new(Str $client_name = 'p6xmms2', Str $path = %*ENV<XMMS_PATH>) {
+ self.bless(*, :$client_name, :$path);
+ }
+
+ method play returns Bool {
+ my Bool $success = self!ok: xmmsc_playback_start($!connection);
+
+ warn 'Playback start failed!' if not $success;
+
+ return $success;
+ }
+
+ # Check for error status from anything that returns an xmmsc_result_t.
+ # Also frees the result value.
+ method !ok(xmmsc_result_t $result) returns Bool {
+ my $command_status = xmmsc_result_get_value($result);
+
+ my $failed = xmmsv_is_error($command_status);
+
+ if $failed {
+ xmmsv_get_error($command_status, my $error-str) and warn $error-str;
+ }
+
+ xmmsc_result_unref($result);
+
+ return not $failed;
+ }
+
+ # FIXME: libxmmsclient has this default $path, but you have to pass a C NULL value as the path
+ # to make it use it, which I don't know how to do using zavolaj yet.
+ submethod BUILD(Str $client_name, Str $path = "unix:///tmp/xmms2-ipc-{qx[whoami].trim}") {
+ $!connection = xmmsc_init($client_name);
+
+ xmmsc_connect($!connection, $path)
+ or die "Connecting via '$path' failed with error: {xmmsc_get_last_error($!connection)}";
+ }
+
+ submethod DESTROY {
+ xmmsc_unref($!connection);
+ }
+}
+
+#####
+# C functions in alphaspaghetti order
+sub xmmsc_connect(xmmsc_connection_t, Str $path)
+ returns Int
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_get_last_error(xmmsc_connection_t)
+ returns Str
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_init(Str $clientname)
+ returns xmmsc_connection_t
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_playback_start(xmmsc_connection_t)
+ returns xmmsc_result_t
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_result_get_value(xmmsc_result_t)
+ returns xmmsv_t
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_result_unref(xmmsc_result_t)
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_result_wait(xmmsc_result_t)
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_unref(xmmsc_connection_t)
+ is native('libxmmsclient') { ... }
+
+sub xmmsv_get_error(xmmsv_t, Str $error is rw)
+ returns Int
+ is native('libxmmsclient') { ... }
+
+sub xmmsv_is_error(xmmsv_t)
+ returns Int
+ is native('libxmmsclient') { ... }
9 t/basic.t
@@ -0,0 +1,9 @@
+#!/usr/bin/env perl6
+use v6;
+use Test;
+use XMMS2::Client;
+
+plan 1;
+ok my $xmms2 = XMMS2::Client.new(:client-name<test>), 'Can connect to xmms2d';
+
+# vim: set ft=perl6 :

0 comments on commit 3d9549c

Please sign in to comment.
Something went wrong with that request. Please try again.