You heard it here first: I’ve started working on a successor to Fandro (at xsamplex), mainly because, firstly, I love diving into these kind of algorithms. Secondly, Fandro’s popularity (for an app written in the Windows XP age) surprised me. Thirdly, Fandro required a reboot, because well, while it still works, obviously, there are issues with the current app. We’re moving to computers with higher DPI screens and 64-bit computers.
For a second I actually considered rewriting Fandro in FreePascal but I’ve decided to focus on C# for now: Yes, that will mean that most likely, I’ll open-source it. And yes, if time permits, I’ll even add side comments about how NOT to do text searches.
No timelines as of yet, though, but technically, the main algorithm was finished a couple of days ago. Time permitting, I expect at least something out by the end of the month.
I‘ve not written a while about programming, let alone anything about that mailing program, RoundAbout. Today’s subject is the Windows TreeView control and its data section, the TreeNodes. As you probably know, a TreeView shows data in an hierarchical way, allowing users to ‘expand’ or ‘close’ so-called TreeNodes, so to expose or hide data they do and don’t want to see. TreeNodes in the Windows world can have user-data attached to it and often, developers will use this to store program specific information. I believe in .Net, this data propery is called ‘Tag': in the Delphi world, it was called plainly ‘Data’. So code-wise this could look like this:
var Node: TTreeNode;
/* FolderData is a pointer to a record */
Node := TreeView.Items.AddChild(Node, FolderData^.Name);
/* Attach the FolderData to the current node */
Node.Data := FolderData;
Early in the process of development, it was noticed that any font or even layout changes caused severe crashes in the TreeView: The TreeView in RoundAbout holds account and message/mail folder information via each TreeNode’s Data member. After a long investigation, I noticed that this was caused by the Delphi TreeView control itself: whenever a window anywhere was refreshed, Windows would send a message to the TreeView control to refresh and recreate itself. Let me say that again: whenever a font was changed in RoundAbout, this would trigger any TreeView to recreate itself. I think this issue was resolved in later versions of Delphi, but I decided to create my own control (PMTreeView, code here) to preserve the data with the following premises:
- Override CreateWnd and DestroyWnd
- Upon destruction of the treeview window, save the data for the nodes to a memorystream.
- Upon creation of the treeview window, (if available) load the node data from the memorystream.
- Trigger an event to notify the developer that the Data structure has changed for further activities.
As I mentioned earlier, I believe in subsequent Delphi versions, Borland fixed this in their own TreeView controls. However, for a piece of code that I debugged and coded in a night or so, my own PMTreeView control wasn’t too bad of an implementation.
Years ago, I used to set up postgres on Debian servers. For a couple of test, I had to install Postgres somewhere: Installing on Windows is generally a breeze, but not needing the third-party tools, I decided to go back to Linux and install the database server on my Ubuntu box. While I didn’t have issues with importing test data/databases, there were minor things that had me briefly stumped. So, to install Postgres on Ubuntu and other Debian flavours, here we go:
- First install postgres by entering ‘apt-get install postgresql’ in a bash-session/terminal
- We need to properly initialize it and I would recommend to add your login user to Postgres: sudo -u postgres createuser -D -P arthur
- Optionally, create a new database: sudo -u postgres createdatabase -O username whateveryouhavefordatabasename
- Open up pg_hba.cfg (sudo vi /etc/postgresql/9.1/main/pg_hba.conf).
- Change the following lines properly (use trust):
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 192.168.2.0/24 trust
- Open up postgresql.conf and set listen_addresses = ‘*’ properly (* means that postgres will listen to all ip-address as defined in networking)
- Restart postgresql
- Connect to postgres using the psql client: psql -U arthur -h localhost -d whichever database
The official postgres site has demo databases (or rather links to them): they are around this url
So, the last couple of weeks, I’ve finally decided to push for a 1.0 release of Convendro (Google Code downloads, Github code): the reason being that I thought it was getting obnoxious that it was still in ‘beta-ish’ mode. After what, 2 years? Come on, pal.
That being said: I’ve mainly focused on clean-up and creating two separate installers for 32 and 64-bits architectures.The irony is that twhe development tool chain literally forced me to deliver two separate installers: First, VS (and the Express edition) has a funny bug (right-oh-here) that kicks in when ever you want to target a full project to 32-bits. My alternative choice, SharpDevelop, does not like targeting 64-bit as ‘there is no x64 debugger yet’. Tough luck and tough shit as a famous rapper once proclaimed: we just change the build to fit the 64-bit dlls and create new installers. Whatever.
So 1.0 out and what’s next? I have no idea, yet. I wrote Convendro because I got tired of WinFF and some other unspecified ‘ad-supported’ conversion tool. I’d love to be able to support more recent versions of ffmpeg. Clever-er parsing of output. Support for other encoders/decoders. How or what, I just don’t know yet.
I‘m surprised how many people look here for help on the .Net 2.0 SerialPort component (reference, which leads to this posting). I have plenty of example code, but I haven’t had time to re-test the project or even try com0com on this 64-bit Windows box. Com0Com (link) does support 64-bit environments, provided that you:
The com0com.sys is a test-signed kernel-mode driver that will not load by
default. To enable test signing, enter command:
bcdedit.exe -set TESTSIGNING ON
What is bcdedit?
No examples for now but my earlier mentioned posting should get you somewhere.
Last weekend, I decided to pick up my Delphi compiler and work a bit on Fandro: in real life, I found out that I wanted to be able to launch Fandro from Explorer’s context-sensitive menu and henceforth, I worked on adding support for this.
I always thought doing Win32 was fairly simple in Delphi. Additionally, Borland used to have excellent demos and sample apps with full sources. However during this short coding stint, I admit, programming in Delphi ended up being sort of a pain, mainly because I’ve been by Visual Studio. And I always thought the language’s assignment statement was silly. There’s another thing of Pascal that has bothered me for ages: the fact that to return values from functions you can use the special ‘result’ variable or the function’s name. As in:
function MyOperation(a, b : integer) : boolean;
result := (Ord(a > b) = Ord( b < a))
function MyOperation(a, b : integer) : boolean;
MyOperation := (Ord(a > b) = Ord( b < a))
I don't consider myself a Delphi programmer anymore: however, don't you just love the part where compiling code actually means generating a stand-alone Win32 application?
Note: I believe that Delphi statement above holds the answer of life and it's this year's Valentine's present to you.
I‘m extremely impressed with the Google Chrome download indicator: for some kind of reason, a circular progress meter makes a lot more sense than a linear one. Maybe it’s because of Pi.
Since I was so impressed and because it was ‘Pi day’ the other day (Pi Day), I thought now was a good time to write a component that does just that: show the progress of something in a somewhat circular form. You can find the code right here: a reminder, it’s C# and that means it is meant for .Net. I’d be really surprised if it wouldn’t work on Mono (it should) [just tested and confirmed that it works].
A couple of notes:
- FillColor is the colour that’s used to fill up the circle
- ForeColor is used for the Text (progress text)
The code should be pretty clear in what it does: I was planning to also paint a bunch of “spokes” in the meter but couldn’t be bothered at the end1. It shouldn’t be too hard (use the sin/cos methods of the Math class to get the right x/y coordinates).
1 Also, this would have given it the Trivial Pursuit look: Google’s progress meter reminds me of that too.
03/16/09: Introduced drawing of Text/Label/Caption.
03/18/09: Good rewrite: Mostly introduction of ‘progressbar’ like properties and methods (Value, Min/MaxValue), Marquee. Introduction of a ProgressType enumeration (maybe should use the regular ProgressbarType). Also, same license (Commercial/personal free use, but please leave the credits in).
I saw that ffmpeg 0.5 was released the other day (I don’t have any link here) and since my Msys/MingW environment was already ready to go I decided to compile my own ffmpeg executable.
I expected it to be ‘an exercise of eating your own hat out of frustation’, however, there are a couple of things you should do to prepare yourself:
- Evacuate your wife, kids, dogs and cats.
- Move your coffee brewer next to your computer.
- Have Kleenex ready for all the spit you probably have to remove from your computer screen.
On a serious note, compiling and finding the sources is not overly hard: The hardest part is to get Msys and Mingw to work right and find the right set of gnu compilers/binaries. If you’ve got that all working, the fun part is compiling the needed packages one by one.
If I can make time, I’ll add an entry how to compile ffmpeg yourself.
Everytime a Wix script (Windows Installer XML) fails to compile, it logs ICE errors. For some kind of reason, whenever these errors or warnings pop up, I keep humming the tune of Vanilla Ice’s “Ice Ice Baby” (Youtube, if you’re so obliged).
I have always been a fan of NSIS (@sourceforge), the Nullsoft Installer System, but I hear that NSIS’s installers don’t run 100% flawless on Vista systems. Wix then, and that’s not because it’s the best system: it’s slow, clunky and the errors are highly Vanilla Ice, Baby.
A couple of years ago, I used to use InnoSetup, but nowadays, I find it too tied to the Delphi language: There’s no doubt in my mind that Embarcadero has great plans for Delphi, but their “reasons why you should buy Delphi” remind too much of the old ‘slogan’ days. You know: “RAD”, “productive”, “rich” and “ease”. I don’t want that: I want Push-Button Spreadsheet Power.
And shit, yo.
Note to self: the source version of ffmpeg comes with h264 presets. Earlier, I mentioned where to get the ffmpeg binary from (note, as far as I can see, the last build was done in 2008), so there may (indeed) other recent versions hanging around somewhere. The presets are in ‘ffpresets’ directory: Most of them seem related to x264 encoding.
I also noticed that the commandline parameters seem to change at the whim of the developers. I already ‘compensated’ for most of these issues, but was rather surprised to find that my ‘latest’ SVN build wasn’t so ‘recent’. Alright, at least we took care of that during the initial design stage.
For more details on specific iPod based command-line arguments, Robert Swain’s ‘iPod video guide’ got me past most of the initial encoding issues.
Added screenshot (see above): Lets see how good the commandline arguments are…
I have been making small progress on my own front-end for FFMPeg (earlier on xsamplex). Earlier I was rounding up the serializers (data persistence, data schmersistence): the threading code was finished months ago. I just have to connect the last dots, which is basically user interface stuff. Most likely I’ll end up redoing some of the serialization but it’s, like I said, pretty much done.
This reminds me of a couple of things: The FFMPeg developers maintain a list of software venders that violate the software’s license (GPL). Their list (“Hall Of Shame”) can be found at the FFMPEG website. Just a couple of seconds ago, I saw a google ad (see picture above) and I thought the name in that ad rang a bell. Oh noes, they’re in the issues trackerz!
I also noticed that a lot of people ask for ‘how to track progress FFMPEG’ and they end up at the very first post I wrote on interfacing with FFMPEG’s command-line. This is not too difficult and requires parsing of the error output (you probably need a state machine too). At one time, a programming board linked here with pointers how to track the frames and translated that to time, which they basically extracted from the bare information that I put in my sample code. I can’t find the link though, so will add that at a later stage.
I thought this article (‘Learning the iTunesDB file format’) was an excellent background on the principles of reverse-engineering existing binary file-formats. I’ve done some ‘clean room’ reverse-engineering too and at the end of the project, I was able to extract and cross-reference data from an existing accounting package. The most interesting part of the process is that after figuring out the patterns and the essential algorithms (reading and writing the proper bytes) every byte just falls into place. To this day, I can still dream up the code, which is a kind of funny. That random-looking 8 or 9 in front of each formatted numeric amount? That was just a joke from the original designers of that accounting package.
So, I have a couple of left over links I’d like to get rid of: Way long ago, I noticed that the ODF (the people who are in charge of the Open Office document specifications) announced the (initial) release of the ODF Toolkit, which includes AODL, a .Net module that supports well, you know, Open Office documents. For a complete set of features, look here.
Months ago, Slashdot featured the topic ‘Please list your Useful Stupid Unix trick’. While the discussion (predictably) heads into the typical Slashdot direction, the posting actually has some good and useful commands and hints:
I’ve seen Windows people go slack-jawed in astonishment as I ssh to the other side of the world and run X programs over forwarding.
Some refuse to believe it, others shake their heads and walk away.
And believe it or not: Unix systems have been able to do that since decades.
During my programming career, I’ve ran into several cases where I absolutely had to use owner-draw to accomplish customized drawing. Originally, as a Delphi programmer, this required knowledge of the specific graphic wrappers around the Windows GDI (and GDI+) functions which Borland (appropriately) called TCanvas. The C#/.Net equivalent is called ‘Graphics’, which (admittingly) does not sound as fancy as Canvas.
That said: in my never-ending quest to fill a niche craving, I decided to look into the basics of photo-editing; that is, on a much smaller scale. The first step was to create a component that (given a specific image), drops a frame on it, which you can use to crop a photo (by either moving it and/or resizing it). Additionally, I always liked how some photo-editors integrate the Rule Of Thirds during cropping of photos, so, that had to be part of the custom-draw routine too.
There are couple of common tasks that need to be taken care of when doing own-draw stuff, all in C# (however, should be similar in Delphi):
- The first thing is to decide which control you’re going to ‘descend’ from, or rather, which control is going to be your base-class
- If your control requires user-interaction (i.e. mouse/key input), you should probably override the control’s MouseUp/Down and MouseMove events. Most likely you’ll need a couple of (private) flags that track down if a mouse button is still ‘pressed’. Add to that a couple of variables that track down the last positions clicked on the screen.
- Separate the drawing routines and call these routines from an overridden OnPaint event.
- Debugging (owner-draw) graphical routines is extremely painful, so think through your drawing routines.
Boring sample code is about to follow.