Saturday, February 16, 2019

Python on Android with Kivy

After wandering around in Android Wonderland with Java, Kotlin, Dart and Flutter; I encountered Kivy, under public development since Feb 2011.  It comes with a recent OSC package called OSCpy which works fine with Ardour if the 'h' 64 bit twos complement integer support is added (parse_long).  I may get around to a pull request for this.

diff --git a/oscpy/parser.py b/oscpy/parser.py
index e080157..7172825 100644
--- a/oscpy/parser.py
+++ b/oscpy/parser.py
@@ -7,6 +7,8 @@ Allowed types are:
     floats -> osc float
     bytes (encoded strings) -> osc strings
     bytearray (raw data) -> osc blob
+    *** added by ssc 2019-01-24
+    64 bit big endian two's complement integer -> osc long

 """
 from struct import Struct, pack, unpack_from, calcsize
@@ -19,6 +21,7 @@ else:
     UNICODE = unicode

 Int = Struct('>i')
+Long = Struct('>l')
 Float = Struct('>f')
 String = Struct('>s')
 TimeTag = Struct('>II')
@@ -42,6 +45,10 @@ def parse_int(value, offset=0, **kwargs):
     """Return an int from offset in value."""
     return Int.unpack_from(value, offset)[0], Int.size

+def parse_long(value, offset=0, **kwargs):
+    """Return an long from offset in value."""
+    return Long.unpack_from(value, offset)[0], Long.size
+

 def parse_float(value, offset=0, **kwargs):
     """Return a float from offset in value."""
@@ -81,6 +88,7 @@ def parse_blob(value, offset=0, **kwargs):

 parsers = {
     b'i': parse_int,
+    b'h': parse_long,
     b'f': parse_float,
     b's': parse_string,
     b'b': parse_blob,
@@ -94,6 +102,7 @@ parsers.update({
 writers = (
     (float, (b'f', b'f')),
     (int, (b'i', b'i')),
+    (int, (b'h', b'h')),
     (bytes, (b's', b'%is')),
     (bytearray, (b'b', b'%ib')),
 )

Kivy can use python 2 or 3 and produce APKs for android so I coded an app based on the ArdOSC layout, available on gitlab at AudioPi_OSC.  I am still developing this, and have stopped working on ArdOSC.

I presented AudioPi and the Kivy OSC app to the NoVALug group on February 9, the slides are online at Audio Pi.pdf.  The YouTube stream is available at "Running AudioPi".