[Gambas-user] Music!

Admin admin at allunix.ru
Sun Apr 17 17:29:32 CEST 2022


Happy easter!
Well, all my software written in Gambas longer then one screen of code 
contains an easter egg. I mean, this is mandatory, isn't it?
And my personal favourite is also about music. I wrote a cash register 
software for my company (huge thanks to you, guys, I would have never 
done it without your help), and the cash register units themselves 
contain a little beeper that can be used pretty freely, the driver takes 
two parameters - the frequency and duration. So I wrote a beeper test 
button, which just beeps once a test button is pressed. Cashiers use 
this button almost just to test the software-hardware connectivity 
rather then the beeper itself, appears to be the fastest way. So I 
thought what if I make it to play a little music after some presses of a 
button. But how do I program a music for this single bit sound source? 
Well, I googled some music for the old cellphones wich had basically 
same sound capabilities, and then I googled the frequencies of their 
"notes". So now, when an operator tests the sound too much, the Mortal 
Kombat theme suddenly plays from that little receipt printing device. 
Their faces are priceless usually. Here's my awkward code (since there 
is no pause, I just use a "silent note" that is _almost_ silent):
-------
Dim music As Integer[]
Dim note As Integer
Dim a3, c4, d4, e4, g4, g3, h3, f3, c5, a4, silent As Integer

a3 = 220
f3 = 174
g3 = 196
h3 = 246
a4 = 440
c4 = 261
d4 = 293
e4 = 329
g4 = 392
c5 = 523
silent = 100

music = [a3, a3, c4, a3, d4, a3, e4, d4, c4, c4, e4, c4, g4, c4, e4, c4, 
g3, g3, h3, g3, c4, g3, d4, c4, f3, f3, a3, f3, c4, f3, c4, h3, a4, 
silent, a4, silent, a4, silent, a4, silent, g4, c5, a4, silent, a4, 
silent, a4, silent, a4, silent, g4, e4, a4, silent, a4, silent, a4, 
silent, a4, silent, g4, c5]

For note = 0 To 61
     libfptr_set_param_int(fptr, LIBFPTR_PARAM_FREQUENCY, music[note])
     If music[note] = 100 Then libfptr_set_param_int(fptr, 
LIBFPTR_PARAM_DURATION, 100) Else libfptr_set_param_int(fptr, 
LIBFPTR_PARAM_DURATION, 200)
     libfptr_beep(fptr)
Next

music = [a4, silent, a4, silent, a4, silent]

For note = 0 To 4
     libfptr_set_param_int(fptr, LIBFPTR_PARAM_FREQUENCY, music[note])
     If music[note] = 100 Then libfptr_set_param_int(fptr, 
LIBFPTR_PARAM_DURATION, 100) Else libfptr_set_param_int(fptr, 
LIBFPTR_PARAM_DURATION, 200)
     libfptr_beep(fptr)
Next

music = [a4, a4, silent, a4, a4]

For note = 0 To 4
     libfptr_set_param_int(fptr, LIBFPTR_PARAM_FREQUENCY, music[note])
     If note = 4 Then libfptr_set_param_int(fptr, 
LIBFPTR_PARAM_DURATION, 200) Else libfptr_set_param_int(fptr, 
LIBFPTR_PARAM_DURATION, 100)
     libfptr_beep(fptr)
Next
-------

Dmitry.

17.04.2022 21:55, Benoît Minisini пишет:
> Le 17/04/2022 à 15:50, Brian G a écrit :
>> Ben,
>>     Really loved the music when I opened Gambas this morning it was a 
>> wonderful surprise!
>>     Thank You!
>>
>> "Failure is the key to success;
>>   each mistake teaches us something"  .. Morihei Ueshiba
>> Brian G
>>
>
> Gambas, the only software with a -true- easter egg. :-)
>



More information about the User mailing list