Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Monday, May 9, 2011

Hello, Vala!

A while ago I've been playing with Vala. The cool thing about Vala is that it's a cutting edge language which is able to produce programs with similar performance to those written directly in C. Obviously, it may prove to be a perfect language for fast audio-processing tasks, and there already are bindings for JACK, liboil (now removed from PySoy), an ongoing effort to create bindings for libsndfile and probably other libraries, which I overlooked.

For the exercise, I tried to create Vala bindings for liblo, the lightweight OSC protocol library. They're still unpolished, but already usable in a straightforward, almost C-like way:
static void main(string[] args)
{
    Lo.Address t = new Lo.Address(null, "8080");
    Lo.send(t, "/box/grid/led/all", "i", 1);
}
Right now, I'm working on Vala bindings for LV2 and the accompanying Lilv library. For this purpose and for further experiments with LV2 plugins I've created uSynth capsula - a project, which currently provides little more than a functional port of lv2jack host from Lilv source distribution. It does not have any support for plugin GUIs yet, but it's a planned feature. Loading GUIs with SLV2 (a Lilv predecessor) worked to some extent:


Capsula is still in the earliest planning stages and doesn't have a roadmap yet. For now, I'm thinking about a full featured LV2 plugin host, completely controllable by OSC. I don't have any further ideas, but perhaps you have? Then, by all means, feel free to join the fun!

Thursday, February 24, 2011

Writing PolicyKit applications in Python without D-Bus

I'm always happy when more libraries get Python bindings, and today I've been especially excited by the fact that GObject introspection support for PolicyKit has finally appeared in Natty repositories. Basically it means, that PolicyKit is now accessible from Python through a native API without direct D-Bus communication. I've tried to port the querying example from PolicyKit manual and it did work!

The Python example below is an almost line-by-line port of the original, but it should give you a basic idea on how to use the API for your own scripts.

#! /usr/bin/env python

import sys, os
from gi.repository import GObject, Gio, Polkit

def on_tensec_timeout(loop):
  print("Ten seconds have passed. Now exiting.")
  loop.quit()
  return False

def check_authorization_cb(authority, res, loop):
    try:
        result = authority.check_authorization_finish(res)
        if result.get_is_authorized():
            print("Authorized")
        elif result.get_is_challenge():
            print("Challenge")
        else:
            print("Not authorized")
    except GObject.GError as error:
         print("Error checking authorization: %s" % error.message)
        
    print("Authorization check has been cancelled "
          "and the dialog should now be hidden.\n"
          "This process will exit in ten seconds.")
    GObject.timeout_add(10000, on_tensec_timeout, loop)

def do_cancel(cancellable):
    print("Timer has expired; cancelling authorization check")
    cancellable.cancel()
    return False

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("usage: %s <action_id>" % sys.argv[0])
        sys.exit(1)
    action_id = sys.argv[1]

    mainloop = GObject.MainLoop()
    authority = Polkit.Authority.get()
    subject = Polkit.UnixProcess.new(os.getppid())

    cancellable = Gio.Cancellable()
    GObject.timeout_add(10 * 1000, do_cancel, cancellable)

    authority.check_authorization(subject,
        action_id, #"org.freedesktop.policykit.exec",
        None,
        Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
        cancellable,
        check_authorization_cb,
        mainloop)

    mainloop.run()

In order to run this example, make sure you have the gir1.2-polkit-1.0 package installed and provide an action in the command line, for example:

./polkit-test org.freedesktop.policykit.exec

I suppose, the API is still a little rough on the edges, but it's already usable and I'm going to try it for an upcoming D-Bus service in indicator-cpufreq. Looks like it's perfect time to start moving things to GObject introspection already.

Friday, December 17, 2010

CPU frequency indicator and DIY merchandise

I have been using Natty since Alpha 1 and I'm very happy with the new Unity desktop. It has surely got its bugs, but I almost love it. The drawbacks are that Unity doesn't support GNOME applets and doesn't seem to have a native application launcher yet. The latter problem is easily fixed by installing either GNOME Do or Synapse. The applets, well... are not a big problem either, because I can't remember using any, except for the clock (replaced by an indicator) and the CPU frequency scaling applet, which had always saved me from all the JACK audio timing issues (with a single click).

There is no indicator for selecting CPU frequency scaling mode, so I decided to write my own. I started with Jono Bacon's tutorial here and used cpufreq-selector D-Bus service (bundled with the Gnome applet) to switch between governors. This functionality is also provided by HAL, but HAL is deprecated in favour of DeviceKit, which doesn't support frequency scaling right now. I think I'll have to add a dedicated D-Bus service in the future to get rid of gnome-applets dependency... And this is how it all currently looks:



Thanks to Quickly, an Ubuntu package was a piece of cake. You can install it from here or grab the source from project page in Launchpad. Please report any issues. Thanks!

Another thing that bothers me, is an almost critical bug with the Ubuntu Beanie Hat from Canonical store. It just cannot stand low temperatures in winter and is unsafe to wear outside. I wonder, if there is a Launchpad project to report bugs against Ubuntu merchandise :) Anyway, I came up with a simple workaround, which works if you're not afraid of DIY:
  1. Get an ushanka.
  2. Attach an Ubuntu button badge (I used a really old one).
  3. Have fun with the new Ubuntu ushanka!

Sunday, November 23, 2008

Back in Black

There are several big changes in Sced expected in the near future, so today I'm releasing the latest stable 0.4 version, that does not introduce any new features, but has fixes for a couple of long-standing bugs.

It's worth mentioning however, that this version is a lot more compatible with stock and third-party style schemes for Gedit. That means, that your SuperCollider code is going to look cool and stylish, even with the darkest of them... Oh, and quite a number of themes is already available through this page at GNOME Live. Go and check them out!



One more thing. In order to make your Gedit even more great and powerful, make sure you also get the fullscreen plugin and the gedit-plugins package from your distro. The former enables the fullscreen mode for the distraction-free coding (or some live demos, perhaps), and the latter has some neat extensions like bracket completion and tabbar-disabler for an even cleaner workspace!

The Sced tarball itself is available through the usual location and the Debian/Ubuntu packages should be already in the PPA at the time of writing. Just in case you missed the installation instructions, check the following post for a short tutorial. And, of course, your feedback is much appreciated.

Friday, January 25, 2008

Sced 0.3 released today!

Okay, the blog is reset, and I have just uploaded the Sced 0.3 tarball to its usual location. This release includes awesome contributions by Eckard Riedenklau and requires gedit 2.20 and gtksourceview 2.0 to run. Enjoy!