A few days ago I started playing a bit with Python and PulseAudio (PA). Long story short I ended up deciding that it would be interesting to create a proper QT4-version of “Volume Manager” that is the most useful too I found for controlling PA properly.
The project is based on Ubuntu’s ‘earcandy’, which is a GTK+-frontend for PA, allowing simple control over PA. Unfortunately someone haven’t told the people developing this about loose coupling and separation into layers.
In the design of of the classes the system has a PA library, which is a binding to the PA module, so Python can access the PA commands and events. On top of this they used a connection class as a wrapper for the library. And this is the place where things go wrong. The connection class is bound to GTK+’s event system, probably to make it easy to connect GTK+ to the PA events.
However this is definitely wrong. Most – if not all – design patterns, and good design principles promotes that there should be a very clear separation from the GUI and the model (in this case the PA server is a data-provider for the model, and the different PA objects, such as sinks and clients, are the model). Below is the diagrams for the MVC and MVVM patterns, for GUI design. Here it should be clear that the GUI (the views) can see the model, but the model cannot see the GUI.
The most important detail in this flaw is the problem it provided me: that I could not just take the model and model providers and use them directly in my application. Therefore I had to remove the GTK+ event calls and currently replace them with pure function calls. In the GTK+-model the events are put on an event thread, which then executes the events while idle. In my further programming I have to research if this is useful or if it is just the way you design events in GTK+.
The further development also showed that the events wasn’t designed with general UIs in mind. This results in some of the events being called unnecessarily when listening for certain events such as a general event for changes i sinks that is both called when a sink is added and the volume changes. These events I want to handle differently.
All these problems and a lot more details will probably result in a more or less complete redesign of the PulseAudioConnection class. This might also enable me to get rid of the GPL, which I consider a major problem. This for instance means that if I should release my work I would need to be able to provide the source at least 3 years after I released it, which is insane. Basically I hope that it makes sense to completely redesign it, so I can get rid of the GPL-problem.