Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Publicaciones sobre programming (publicaciones antiguas, página 6)

On speaking and slides

As I men­tioned be­fore, I was at the 3rd CafeL­UG event on fri­day and sat­ur­day.

It was a pret­ty large even­t, rough­ly 1300 pople, 63 con­fer­ences.

I had two of my own, and here's how they wen­t:

Fri­day: The PyQt/PyKDE one. Au­di­ence: about 50 sit­ting, 15 stand­ing. I had no time what­so­ev­er to pre­pare this. But I was luky enough to have some­one (thanks Cris­tian!) lend me a note­book, and so I spent the pre­vi­ous con­fer­ence (pf/OpenB­S­D) work­ing on mine :-)

I kept it on a low lev­el, noth­ing too com­pli­cat­ed, since I on­ly had 60 min­utes, but the au­di­ence seems to have liked it. Or at least they found my at­tempts at ex­pla­na­tion fun­ny.

Any­way, noone was dis­gust­ed enough to tell me to my face, and I had a gen­er­al feel­ing of it hav­ing been good.

I was able to show a quick do-noth­ing app in 20 lines of code, and show sig­nals and slot­s, and re­al­ly re­al­ly push the idea of in­ter­pret­ed lan­guages as bet­ter for hob­by pro­gram­ming (which I think is the right path). Not too many ques­tions right then, but about a dozen kids at­tacked me with ques­tions on the hall af­ter leav­ing.

Sat­ur­day: My gener­ic KDE-­for-be­gin­ners speech. Au­di­ence: 100 sit­ting, 10 stand­ing. I was a bit too heavy on the philo­soph­i­cal, but it went down nice­ly. Sev­er­al of the guys from fri­day's PyQt ses­sion were there, so more ev­i­dence it did­n't suck too bad­ly.

It was fun, peo­ple were sur­prised by Og­g-rip­ping from Kon­queror as usu­al, some fun, sev­er­al ques­tion­s.

All in al­l, a nice cou­ple of ses­sion­s, and I think I did well, which en­cour­ages me to do it more of­ten. Who knows :-)

What linux needs on the desktop is...

... oh, screw it, why not say what it does­n't need? It's bet­ter for my blood pres­sure.

  • It does­n't need Be refugees whin­ing about how BeOS was so awe­­some and Lin­ux desk­­tops suck. You know what, guys? If BeOS was so cool, and Lin­ux sucks so much, how come BeOS is dead? Now put a sock in it and go prac­tice your OS­­-necrophil­i­a.

  • It does­n't need win­­dows users say­ing "it's not like win­­dows, it suck­­s". If Lin­ux was just like win­­dows, you would say that there is no rea­­son to switch, so put a sock in it, be­­cause you can't have it both ways.

  • It does­n't need Mac users say­ing how there's no point work­ing on it be­­cause OSX is al­ready as good a unix desk­­top as there's gonna be, so why both­­er?. Put a (de­sign­er) sock on it, be­­cause in or­der to use OSX you have to buy an un­­god­­ly ex­pen­­sive (ex­­cept the 12" ibook, that's kin­­da cheap and cute) com­put­er that pro­­vides on­­ly ad­e­quate per­­for­­mance, and I am a cheap bas­­tard.

  • It does­n't need old unix gu­rus ex­­plain­ing how there's no need to work on KDE or GNOME be­­cause Win­­dow Mak­er is lighter, and all that's need­ed is a way to keep their xterms sort­ed. Put a sock in it, be­­cause xterm suck­­s, Win­­dow Mak­er is fea­­ture­­less, and you can't do any­thing use­­ful for a reg­u­lar us­er with just xterms and Win­­dow Mak­er, so you are com­­par­ing ap­­ples to ap­­ple or­chard­s.

Most of al­l, it does­n't need any "What lin­ux needs on the desk­top" ed­i­to­ri­al­s.

On oth­er news, I will be speak­ing about Lin­ux on the desk­top at the UADE in Buenos Aires, Ar­genti­na, this sat­ur­day, and about PyQt/PyKDE pro­gram­ming this fri­day.

More in­for­ma­tion at the CafeL­UG site. If you read it here and men­tion my blog, I will pay you a beer (of­fers lim­it­ed to a max­i­mum stock of three beer­s).

On other news today...

Python code re­al­ly does­n't look good on plan­etkde, so fol­low the link to my page to see it right if you are there ;-)

Adventures in Hi-Fi

As I blogged ear­li­er I am writ­ing a game (and yes, it's pret­ty much playable al­ready).

One thing I did­n't men­tion is that I nev­er wrote a game be­fore. Yeah, I know ev­ery­one does it as one of his first pro­ject­s, but I nev­er did.

So, there are some things I re­al­ly have no clue about 1, like sound and mov­ing graph­ics around.

For the graph­ics stuff, QCan­vas is just fine and dandy, but to make things bloop and war­ble and squeak when the time is right, I found Qt's sound sup­port some­what de­press­ing.

Come on, NAS? Who us­es that? And what about mu­sic? I had no idea.

So, I start­ed try­ing to fol­low one of my lead­ing prin­ci­ples of de­vel­op­men­t: find a way to make it Some­one Else's Prob­lem (T­M).

The usu­al way to do that is find­ing a li­brary that han­dles the prob­lem, write min­i­mal glue, stick it to the side of the pro­gram, tell the pro­gram that's his new ar­m, and for­get about it quick­ly.

Here's what I found.

Mi Dios!

I thought I should start by adding one of those an­noy­ing lit­tle tunes ev­ery game has. It's just a game tune, I don't want to have to in­clude a 3MB OGG file for it, so I want­ed an in­stru­men­t-based for­mat.

I re­mem­bered MI­DI tunes. You may know them as ring­tones nowa­days, but they used to be just cheesy tunes gen­er­at­ed by your SBPro's FM gen­er­a­tor, not your phone.

In fac­t, I re­mem­ber hav­ing a lit­tle prog­gie called playmidi, that would do that in Lin­ux.

Well, it seems that in the past few years, ei­ther sound cards have for­got­ten how to play them, they fell out of fash­ion, or some­thing, be­cause the on­ly things I found that could play MI­DI are mon­strosi­ties that re­quire a 9MB dig­i­tal in­stru­ment set. And how was I to in­clude that along with my 25KB game???

So, what's nex­t? I had a C64, so...

MOD me up!

MOD files are like MI­DI files, on­ly the MOD in­cludes it's own in­stru­ment set, called sam­ples, and in­struc­tions on how to re­peat and al­ter those sam­ples to make a tune.

Good news: there are nice-­sound­ing, fun­ny MOD files that are about 30KB in size.

Bet­ter news: There is a pop­u­lar li­brary to play them! It's called Mik­mod, and your dis­tro has it (and it's a de­pen­den­cy for KDE's mul­ti­me­dia pack­ages too).

Even bet­ter news: It has sup­port for play­ing sim­ple sounds (sam­ples in mod lin­go) by call­ing a cou­ple of func­tion­s.

Awe­some news: It in­cludes a soft­ware mix­er so you can just tell it to play this, then play that, then that, and a tune in the back­ground, and ev­ery­thing sounds at the same time.

So, we have a win­ner. This ba­by can han­dle ev­ery­thing I need for the game!

But... is that a snake in your pock­et?

I can't find a Python bind­ing for it. I am sure as soon as I post this ar­ti­cle some­one is go­ing to come up and tell me, here they are, mo­ron! But I just can't find any.

So, I de­cid­ed to do some­thing I want­ed to do al­ready and learn to use Pyrex. Pyrex is a tool to write python ex­ten­sion­s, with al­most-free ac­cess to C li­braries, in an al­most-python lan­guage (on­ly mi­nor syn­tax dif­fer­ences).

That way, I could write a Python mod­ule to use Mik­mod.

You know what? It was al­most scar­i­ly sim­ple 2. I did­n't wrap all of Mik­mod 3 be­cause I don't need it, but now I can do stuff for games and apps al­most triv­ial­ly.

Even more: Pyrex has awe­some dis­tu­tils sup­port, so build­ing the ex­ten­sion­s, usu­al­ly a pain in the rear, is triv­ial (most­ly you just copy and delete stuff, with some search and re­place).

One thing I found I did nice­ly is this: Mik­mod re­quires you to call Mik­mod­_Up­date ev­ery once in a while so it fills the sound­card's buf­fer with stuff to play. If you don't, it skip­s.

So, I just start­ed a thread that loops and takes care of it. You don't even have to know about it to use the ex­ten­sion. Oh, sure, if your Mik­mod is not thread­safe, it break­s. Well, get a de­cent Mik­mod pack­age, then.

How does it look?

Here's a whole noisy prog­gie

#Load the modules
import mikmod, time
#Init the library
mikmod.init()
#40 voices, 20 for music, 20 for random sounds (overkill)
mikmod.setNumVoices(20,20)
#Enable sound, starts the thread that pushes sound, too
mikmod.enableOutput()

#Create a module, that is, a music track
module=mikmod.Module("BasicInstinct.mod")

#Load two samples, just a couple of noises
s1=mikmod.Sample("lost.wav")
s2=mikmod.Sample("swap.wav")

#Start playing the song
module.play()


#For the duration of the song, each second, make some noise


while module.active():
        s1.play()
        time.sleep(0.5)
        s2.play()
        time.sleep(0.5)

#Close the mikmod library, stop the thread, etc.

mikmod.exit()
1

As if that would sur­prise any­one!

2

On the oth­er hand... wait­ing for stuff to com­pile... how quain­t.

3

Ac­tu­al­ly, I am wrap­ping al­most all of Mik­mod, I am just not ex­pos­ing it to Python be­cause I don't need it.


Contents © 2000-2020 Roberto Alsina