音時雨 ~Regentropfen~

❆ YACF -- Yet Another Code Fight

snippet 1.
Earlier in this week I got to listen to some one singing the song "Lady Jane" by the rolling stones, and I began to laugh before the song finished. The reason was straightforward, the lyrics is so embarrassing! How could they wrote it and actually sang it? (Leporello: If he continues, I'll laugh.) In this sense, Noriko's dark love songs are way, way better!
snippet 2.
I think I won't to be able to play a cello ever -- The true thought after looping Mozart's Rondo K.617 for hours. I stopped every time when the cello floats up. It's just too erotic to make me concentrate! (;´∀`)
snippet 3.
Big blame for Haruka's 10th anniversary premium box and the two Biohazard Revelation games, I'm now in parsimonious mode and have cancelled the original plan of getting a Xperia M4 or Z4 (unless my current Arc breaks into 5000 pieces).
snippet 4.
As of the game "Zero Nuregarasu no Miko", no matter for how many times I look at Kozukata Yuuri, I think she's like Rorona from the Atelier series, in terms of both the hairstyle and the clothing.
☆.。.:*・゚☆.。.:*・゚☆.。.:*・゚☆.。.:*・゚☆.。.:*・゚☆.。.:*・゚☆.。.:*・゚☆
...and now the whole story:
It could be my longest record for a text parser script, spanning over 10 days. The concept doesn't sound complicated, but since we're asking the machine to work for us, we get to spend time making it happy.
While not being the most capable free software, I had no intention to switch from Aria Maestosa to another midi sequencer, which was because of not only its name but also its XML based save files. Its biggest drawback for me is that it can't produce a nice printout of the score. Later on, "Lilypond" showed up in the top hits when I searched for a sheet music printing software. When I read about it uses a text-based input, my brain was ready to initialise another code fight, that could bridge the two.
The idea didn't sound hard: you read through Aria XML by track, take each pitch and its length, and convert into the Lilypond format. But meanwhile, you have to consider when the notes overlap, with or without being of the same duration, different names for the same pitch, dotted notes or triplets, etc. Since Aira only supports one key signature per track, and the time change is applied to all tracks, the only big problem was how to organise the notes. After scrapping off a few pages, what I ended up was a rather complicated structure (once again I really love references!):
$score->{$track_number}{track}=[
	[
		[
			[
				[
					{
						pitch_number=>4~119 || 0,
						pitch_base_note=>1/2/4/8/16/32/64,
						pitch_has_dot=>1/0,
						pitch_is_triple=>1/0,
					}
				], #pitch1
				[], #pitch2
				...
			] #chord1
			[], #chord2
			...
		], #voice1
		[], #voice2
		...
	], #measure1
	[], #measure2
	...
];
I was indeed lost for so many times and during the early stage of designing the main structure, I kept inserting and commenting out "print Dumper $xxx; die". (;´∀`)
Of course I'm aware of it can never be perfect: it has mysterious issues with triple timing, will mis-calculate double dotted notes' durations (not a big deal as I rarely encounter double dotted notes), can't automatically produce grace notes and composer info (how much you can expect from a midi file?), requires manual editing to change keys, modify track names, add other marks, or this or that. But for my personal use, it's good enough. Finally there's a way to print nicely formatted sheet music in any key, or with transposition (which can be done in either Aria, Lilypond or my script).
The Outcome:

[1] which helped me testing the ground basics and revealed the issue with triplets.


and,
[2] which gave me a chance to look at more about layout formatting and also disclosed a stupid yet severe bug in mapping pitch to note names.