New gedit goodies

Just a quick update of what I’m currently working on:

clang integration in gedit

That’s right, that’s clang integrated in gedit (with the very nice libclang). For now only error reporting is implemented but libclang will also gives us the AST (allowing fancy stuff like static analysis, referencing, symbol browsing, etc.). In addition, there will be auto completion in the near future.

You can’t test this, you can’t find the code yet anywhere, this is just to tease you.

Posted in gedit | 20 Comments

Rhythmbox webinterface plugin

A while ago I managed to buy an iPad. I am using/planned to use it for various things. One of those things was to be able to remotely control my music player (which is nice when sitting outside on the terrace, having a small party etc.). The ‘Remote’ application that exists to control iTunes works really well, however I don’t really use iTunes. So I thought I would have a look on how to do something similar with Rhythmbox (or Banshee for that matter). I remembered something about DLNA and uPNP and tried for some days to get this to work, but I really got nothing. I don’t know which side is to blame, but in the end I gave up trying to make it work.

Then I thought it might work just as well through a webinterface, why not. I looked for a suitable plugin for rhythmbox, but unfortunately most of the 3rd party plugins are not ported yet to 3.0. Since I thought it would be fun and a nice opportunity to employ some of that shiny, new and hip css3/javascript/jquery/ajax/websocket, I made a plugin for RB to do just what I want.

TeleMote Rhythmbox plugin

It features all the basic things that I want from a remote control. It will show you a list of playlists/sources, followed by a list of artists (for the selected source) and finally a list of songs for the selected artists sorted by album. You get the basic controls to play/pause, skip songs, repeat/shuffle and control volume. In addition, you can also set the current selection as the current playlist. Finally you can also simply queue some songs (those blackish boxes at the bottom of the screenshot) which will be played as soon as the current song ends playing (this is all just rhythmbox functionality exposed and nothing new).

There are some fancy (useful) animations in the UI and in general I kind of like the look of it. I wouldn’t call myself a “designer”, so if anyone wants to jump in and improve some css, please feel free. The plugin is hosted on github:

http://github.com/jessevdk/telemote

Note: You can save your breath preaching about how Apple is evil etc, I’ve heard it all before…

Posted in gedit | 19 Comments

gnome 3.0 for application developers

I wanted to write a little post on what it means for application developers to try to get ready for GNOME 3.0. Many people might already realize what I try to outline here, but I think it’s still good to show. This will be specifically about gedit (naturally), but I think it will apply to any applications trying to survive in the storm that is GNOME 3.0.

I have been developing for gedit since around 2006 (this is 2.14). I would not say I’m the most active developer at all times, but the fact is that gedit is almost solely being developed by volunteers (we see little to none contributions from financed developers). This is of course true for many open source projects. gedit seems like a simple enough little application, but it’s still quite extensive.

Our normal development cycles are relatively uneventful. We introduce a small set of new features, fix some bugs, etc. We also always try to ensure that current HEAD of development is “stable”. This means that I have always used current HEAD in a production environment, that’s right, production! This means it gets a lot of testing, because it is the application I work with most every day. We are not usually early adopters of new technologies, which helps this level of stability.

This changed with GNOME 3.0. We decided we would try to adopt to the changes as early as possible, so that in the end we actually have gedit ready to be shipped. This meant however, amongst other things, the following:

  • A lot of work to port from “old” technologies (gconf – gsettings, pygtk – pygi)
  • Half of the time I’m just trying to get jhbuild to work again
  • gedit is continuously broken due to API changes or broken dependencies
  • No real testing because it’s unusable in a production environment
  • Regressions are almost inevitable
  • No real change for end users!

Now, I of course understand also the advantages of trying to get this to work, but it has been largely demotivating for our little team. To illustrate a bit the impact of this, I had git crunch some numbers on our development cycles.

On this plot you can see the sum of all added and removed lines (excluding translations) over all commits in a particular development cycle. As you can see, we have seen a significant increase of activity in this cycle. Of course, not all of this can be attributed to GNOME 3.0, but there is an undeniable effect. If we zoom in to the last two development cycles, we can see who the person is that we really need to thank:

That’s right, Ignacio is clearly our hero! Anyway, I just want to point out that this cycle has been particularly hard for application developers, especially those that try to adopt early so that they are actually ready by the time GNOME 3.0 lands. And then to think, for the end user, there will be basicly no change at all…

P.S. Note that if you apply a simple COCOMO to this (you take an “organic” type of project, for 80 KLOC (which is probably an overestimation, but still)), you get some 20 months of volunteered work done by a team of 12 for this cycle… wow…

Posted in Uncategorized | 8 Comments

Fun with gstreamer (controlling volume of channels independently)

Recently I wanted to use gstreamer to add some very basic audio support to an application. I just used the playbin element to play audio files and added some logic to control volume (easy enough with playbin since you can just set it directly) and looping a sound N number of times (which is also easy enough, since you can just watch EOS on the pipeline, seek to the beginning and play again).

There was however one thing that I wanted to implement that left me a bit puzzled. I wanted to control the volume of each channel of an audio file independently. The why is not really important. My first thought was to use the “volume” element. It implements the GstMixer interface, which supposedly could be used to control independently the volume of each of the channels. Easy enough, right? Wrong… Even though the volume element implements the mixer interface, it does not actually implement the part where you can control the volume of each of the audio channels. If you look at the mixer track, you just see one channel.

So what can you do? It turns out that what you need to do is to take your audio, deinterleave the multichannel audio into single multiple mono channels. Then to put a volume element of each of those mono channels and finally to interleave those channels again. Even though this is maybe still relatively simple, it took me quite some time to figure it out. Anyway, here is the pipeline that would do this:

gst-launch-0.10 -v filesrc location=audio.wav name=src ! decodebin ! deinterleave keep-positions=true name=d interleave name=i ! autoaudiosink d.src0 ! queue ! volume volume=0.5 ! i.sink1 d.src1 ! queue ! volume volume=1 ! i.sink2

This would play the file “audio.wav” with the left channel at 0.5 and the right channel at 1. Note that I had to put keep-positions to true on the deinterleave element (although I don’t know exactly why, it seems to have something to do with the pulsesink element: #657457.

Since I’m a gstreamer newbie, please let me know if there is something I misunderstood about all of this, or if there is a better way to do what I want.

Posted in Uncategorized | 2 Comments

On cycling

I saw some posts on pgo recently on cycling, so I thought it would be a good occasion to do the monthly or so blog. Cycling is something very natural where I come from (which is flatland), but since it’s literally flat everywhere there is not that much to it. For instance, I used to have a bike with no gears, and you break by peddling backwards. This is not really the case where I live now (which is Switzerland, Lausanne). So, in order to get a bit into shape (and loose some kg’s) I started to do some more cycling here, mostly short trips of 2 hours max, but with quite a bit of climbing (at least for me :)) which is nice!

Today I decided I was up for something more, so I went from Lausanne to Geneva and back, which totals at around 120 to 130 km (give or take, the route on the map is not exactly how I went and I didn’t track GPS and also don’t have a km counter) in 6 hours. I must admit that the last 30 or so kilometers where pretty hard on me (since I’m really just a beginner) and I also did it with a mountain bike (I’ll hopefully have a racing bike soon). Anyway, my legs are burning quite nicely. More cycling!


View Larger Map

Posted in Uncategorized | 4 Comments

guitar software

Dear all,

I’m looking for a nice piece of software that will assist me in my recently revitalized guitar playing activities. What I would like is really just a tool for my convenience in playing along with songs that I like. Therefore I’m looking for the following features:

  1. Load an MP3
  2. Load/edit corresponding tablature
  3. Be able to slow down the song (without changing the pitch of course)
  4. Be able to silence/muffle the guitar part of the song
  5. Have a nice interface, not something that looks like Win 3.11

As you can see. It’s really not that much. In addition, the following I would consider a bonus:

  1. Figure out/specify tablature timing with regard to the song and show where in the tab the song is while playing
  2. Integration with GNOME where possible
  3. Searching for tablature
  4. Automatic tablature extraction from a song

Anyone knows about some open source project that has at least the 5 features listed at the top?

Posted in Uncategorized | 9 Comments

gitg – git repository browser

With the latest release (0.0.6) just out the door I think it’s about time to write a little post about one of my pet projects, gitg. I guess most people will think ‘argh, not yet another git GUI’, but hear me out :)

I was trying to understand git, but found the initial transition (as many other people) a bit hard. So, I thought what better way to learn, then to write a gui client. Born was gitg 0.0.1. The purpose of the project was to provide a GitX like application, targeted at GNOME. It had to be fast, nice looking and generally useful (as you can see in the left screenshot, it loaded the linux repository of 20.000+ commits in under a second).

gitg showing the linux repository

gitg commit view

The latest version which has just been released has quite some features already, including:

  • Show repository history using ‘git log’ syntax
  • Commit mode featuring per-hunk staging
  • Basic fetch/push/merge/rebase functionality
  • Cherry-pick
  • Drag and drop rebase/merge
  • Drag and drop format-patch export
  • View and export repository file tree at any revision
  • Tag support
  • Stash support
  • Basic remotes management

In any case, if you want to give it a spin, it’s a vailable in the latest debian and ubuntu (I don’t know about other distributions), but the version is a bit outdated. For the latest and greatest:

Download: ftp://ftp.gnome.org/pub/GNOME/sources/gitg/0.0/gitg-0.0.6.tar.bz2
File a bug: https://bugzilla.gnome.org/browse.cgi?product=gitg
Get it from git: git://git.gnome.org/gitg
Posted in gitg | 35 Comments

gedit gobby collaboration

After some more hacking we have most of the functionality ready for real collaborative editing in gedit. Here is me and Armin collaborating (me with gedit and Armin with gobby, sorry, interface in Dutch):

In contrast to my previous post, this version now properly handles its sessions, does error handling etc. The only thing that is really missing right now is undo/redo, which is tightly coupled to GtkSourceView at the moment in gedit. We would need to make the undo handling less specific to use infinote undo/redo for shared documents.

When all of this more or less works, the next step will be to use telepathy tubes to allow sharing documents directly with one or more of your contacts. The idea is that you can offer a collaboration session to your contacts. gedit will then internally run an infinote daemon, offering a virtual document store made up of the open documents in the gedit window. All the necessary components are there, so it should be fairly straightforward to do.

To finish, a little teaser screencast: (youtube, ogv)

Posted in gedit | 11 Comments

gedit collaboration plugin

Just finished a big chunk of a new gedit plugin which uses the excellent infinote library (gobby, libinfinity) to do collaborative editing. Being pretty tired, I’ll keep this post short, but be sure to get an update on the plugin’s progress soon :)

Credit goes to the rocking infinote API and Armin from gobby fame, where all the hard work is done. The code plugin is currently hosted on github, but we will most likely move it to gedit-plugins once it matures. If you want to try it out, be sure to fetch the libinfinity 0.4 stable branch from git (there were a few API additions and small bug fixes to make it work with gedit).

Posted in gedit | 19 Comments

About snippets

I think most people know that besides being a very light weight, and simple text editor for GNOME, gedit can also be “transformed” to a more powerful editor using the many plugins is supplies. One of those plugins is the Snippets plugin, and I would like to point out some of its more advanced features that even most of the gedit developers don’t know about.

Snippets is featured by virtually all source code editors in one way or another. It provides an easy way to insert/activate small templates in your document with some variables, or placeholders to quickly suit it to your specific use case. Placeholder can have default values, you can mirror placeholders in multiple locations, and you can specify where the cursor needs to end up when all the placeholders have been visited (you can read more on basic functionality of snippets in the gedit help). I would like to discuss four features that might be less well known.

1. Python placeholders

Python placeholders are placeholders that execute arbitrary python code to provide the text to be placed at the placeholder location. The placeholder syntax is as follows:

$<n:[k]: python code [return string] >

Here n is the optional placeholder tabstop as with other placeholders. If a python placeholder does not have any dependencies (implicit or explicit) on other placeholders, you will be able to tab to it by that tabstop. The tabstop can also be used to refer to this placeholders’ contents in other placeholders. The second optional modifier is [k], where k is one ore more comma separated tabstops referring to other placeholders. These indicate explicit dependencies (I’ll explain them later).  In the python code, you simply return the string you want at the placeholders location. In the code you can use gedit environment variables for snippets (like $GEDIT_CURRENT_DOCUMENT_PATH) and references to other placeholders (using $n). This will provide you with a kind of mirror placeholder doing a particular transformation on one ore more other placeholders. Python variables can be shared between multiple python placeholders  using global. This is where explicit dependencies come into play. Snippets does not automatically find out that another placeholder might depend on a change in a global variable, and thus should be updated. Defining the dependencies explicitly ensures the placeholder will be updated when any of its dependencies has changed.

For an example of this more advanced functionality, take a look at the gobject snippet provided for C headers and C sources. It makes extensive use of the python placeholders and is quite a nice way to bootstrap gobject classes.

2. Regular expression placeholders

Python placeholders are very powerful, and using the re module, you can do regular expression substitution quite easily. However, regular expression transformations are quite common, and a special placeholder is available which makes it easier and cleaner to use regular expressions. The syntax is the following:

${[n:]input/regular expression/substitution[/modifiers]}

Here n is the usual tabstop, input is the text on which you want to apply the regular expression. This can be either another placeholder (a number) or an environment variable such as GEDIT_SELECTED_TEXT (useful when you activate the snippet on selected text). The regular expression is a regular expression conform the python re module. This will be searched for in the input (note: this means it does not have to exactly match the input). The last part specifies how to substitute the match. Here you can use \n to backreference matched groups in the regular expression. Additionally, a special syntax allows you to apply a small number of transformations on the backreference using \<n,modifiers>. Modifiers can be one or more of the following:

  • U: Uppercase the matched group
  • L: Lowercase the matched group
  • u: Uppercase only the first character of the matched group
  • l: Lowercase only the first character of the matched group
  • t: Title case the matched group

Combining them can be useful if you want to want to capitalize only the first word, for example: \<0,Lu>. This will first lowercase the match, and then uppercase only the first character.

The last part of the regular expression placeholder specifies a set of optional modifiers for the regular expression matching equal to the modifiers in the python re module. One last feature is the use of conditions in the substitution part of the placeholder. Using the syntax (?n,truepart,falsepart), you can substitute a group depending on whether it matched or not (useful for optional groups). These can also be nested, so you can build more complex conditions.

3. Dynamic snippets

A new feature was recently developed and is currently available in the development releases (2.29.x): dynamic snippets. Snippets now exposes two functions on the gedit internal message bus (which is used to enable inter plugin communication). The message bus is similar to how you would use dbus, but just for internal use. It allows plugins to hook into each others functionality (for example, you can manipulate the file browser plugin in many useful ways using the bus). For snippets, the following two messages are available:

  1. /plugins/snippets.activate (trigger[, view, iter])
    When this message is send, the snippet corresponding to the tab trigger <trigger> is activated. You can optionally specify the view and iter where to activate the snippet, by default the current view and cursor will be used.
  2. /plugins/snippets.parse-and-activate (snippet[, view, iter])
    This message enables the dynamic snippets. Basicly, you provide the full snippet and optionally the iter and view where to activate it. This provides a very powerful mechanism to use all of the power of snippets from other plugins. I use this in one plugin (gedit-commander which I will talk about at some point) to dynamically build a snippet for a doxygen documentation of a function declaration.

4. GtkSourceCompletion integration

The last thing I want to show is the recent integration with gtksourcecompletion nacho recently blogged about. Before, snippets implemented its own completion popup for when there are multiple snippets with the same trigger. This popup was really quite horrible and had a lot of usability problems. This has now been resolved in the development version (2.29.x) using gtksourcecompletion. One additional feature is the use of multiple default values for placeholders. Using the syntax ${n:[value1,value2,value3]}, you can provide multiple choices for the default value. When you tab into this placeholder, a completion popup will show you the available choices so that you can quickly pick one. This is particularly useful for example for CSS snippets, where some CSS properties have a specific set of valid options.

Defining a placeholder with multiple defaults

Defining a placeholder with multiple defaults

Activating the snippet

Activating the snippet

I’ll try to occasionally highlight other hidden gems in gedit, until then…

Posted in gedit | 9 Comments