
@stchang Hi I just saw a post on Reddit and decided to ping you. https://www.reddit.com/r/Racket/comments/svo0xf/is_pasterackorg_down/

I have a little racket script that when I run (for testing), does something like:
(define frame (new frame% ...))
(define canvas (new canvas% ...))
(define timer (new timer% ...))
(send frame show #t)
The timer
is repeating, but I have no way to stop it once started. Is there some nice thing I can do after defining timer
to make it so that when frame
is closed the timer is stopped?

I’m confused. You can use (send atimer stop)
to stop a timer, and you can use (send aframe show #false)
to close a frame

@massung The class frame%
has an on-close
, so you could make an my-frame%
class with an on-close
that invokes (send timer stop).

After reading @soegaard2’s reply, I get it now. Yes, you need to override on-close

Yeah, that’s considerably more effort than I want to put into a stupid test at the end of the script. Maybe it’s not as bad as I’m thinking tho.

I was hoping there might be some cool use of augment
from outside a class
definition I could use.

@massung I am working on a little pacman game using Sketching - and now I want to add sound effects. I have the sounds as wav-files. I see that you use SFML in r-cade. Do you think it would be a good use case - or is it overkill to use SFML?

#lang racket/gui
(define fr (new (class frame%
(define/augment (on-close)
(displayln "on close"))
(super-new))
[label "Frame"]
[width 400] [height 400]))
(send fr show #t)

the SFML will come with tons of extra stuff you likely don’t need. It really depends on your sound needs. If you need mixing, etc. then it’s probably a good idea to go with that - or something similar that supports it. If you just need “play-wav” and don’t care about panning, mixing, attenuation, etc. Then use something else. :slightly_smiling_face:

Also, if you already have the WAV (or OGG) files on disk, then a simple “play sound” function will likely be your best bet.


If you want to muck with wave forms or envelope functions, though, then you’ll need more

I need a little more than play-sound
from racket/gui
but not much. It seems play-sound
only plays from a file - and it feels like there is a delay. It would be better if I could load the sounds into memory and play them from there. Maybe I need something that can queue sound effects - I am not sure. I’ll refrain from going into the synthesizer rabbit hole for now :wink:

Maybe two sound effects at once?

check whether waves are cached though, in which case you pay the loading part only once

if they are not, that may be worth adding :stuck_out_tongue:

Audio is one of those domains where it’s easy to do the basics, but much beyond that and you’ve followed a white rabbit down a hole. :wink:

> I’ll refrain from going into the synthesizer rabbit hole for now Haha! Just now read that!

Sometimes I forget I don’t have to define
a derived class to use a derived class. :wink:
Thanks for the reminder!

On Linux an external tool is invoked to play the sound.
On macOS there is no caching. https://github.com/racket/gui/blob/d1fef7a43a482c0fdd5672be9a6e713f16d8be5c/gui-lib/mred/private/wx/cocoa/sound.rkt#L20

I like what you did in r-cade btw. You made the tools to get the real 8-bit sound.

If you ever want to go down the synthesizer rabbit hole, though, hit me up. I’ve done that kind of programming for multiple games. I know way more about it than I would like to know.

Thanks. I tried to make it simple but still allow for complex stuff to happen.

Some people write (super-new)
on the class
line to save a line. It looks ok IMO: #lang racket/gui
(define fr (new (class frame% (super-new)
(define/augment (on-close)
(displayln "on close")))
[label "Frame"]
[width 400] [height 400]))
(send fr show #t)

I will - I know a little already though.
In a Christmas holiday some years back I got the idea that Racket needed a SID emulator… The project is 95% complete and it still bugs me I didn’t finished it. It’s impressive how detailed the information available is on the old chips.

@massung Consider making a package csfml-libs
that contains the shared libraries. That makes it easier to quickly try csfml
without needing to install extra libraries. [An example: https://github.com/soegaard/poppler-libs ]

How would I go about referencing it in csfml
(e.g. how would Racket know where to look for those dynamic libraries)?

In the info file of csfml
you can use #:platform
. The info file of racket-poppler looks like this: #lang info
(define collection 'multi)
(define version "1")
(define deps '("draw-lib"
"slideshow-lib"
"web-server-lib"
"base" "pict"
("poppler-x86-64-macosx" #:platform "x86_64-macosx")
("poppler-i386-macosx" #:platform "i386-macosx")
("poppler-win32-x86-64" #:platform "win32\\x86_64")
("poppler-win32-i386" #:platform "win32\\i386")))
(define build-deps '("at-exp-lib" "rackunit-lib" "scribble-lib"
"racket-doc" "draw-doc" "pict-doc"))
https://github.com/soegaard/racket-poppler/blob/master/info.rkt

Hmm. I wonder whether racket-poppler works on M1?

Okay, that’s good info, but I meant at runtime for loading the dynamic libs. Does racket look in the deps folders for them?

How do you say “I feel clueless because I don’t know the context, what’s called ‘zuo’?”?

The info file for the shared library for macOS looks like this: #lang setup/infotab
(define install-platform "i386-macosx")
(define copy-foreign-libs '("libpoppler-glib.8.dylib" "libpoppler.44.dylib"))
The effect is that the shared libraries are copied to the folder, where Racket usually has the shared libs.


The copying must happen when raco setup poppler-libs
is run.


Thanks. :smile:

If you don’t want to override the frame’s on-close
method, you could change the timer’s callback to check whether the frame is-shown?
, and stop the timer if not, but you’ll have to manage things so it doesn’t confuse the not-yet-shown and was-shown-but-now-closed states.

Apropos the sound rabbit hole. The authors of the “The little book of sound chips” 1–4 definitely fell in.
I notice that the “square” wave actually wasn’t perfectly square - I wonder how large an impact it has on the sound.
https://c64audio.com/products/the-little-book-of-sound-chips-volume-1

@chansey97 and other Chinese speakers: is that meaning common/bad enough that I should look for another word? I worried that using an especially common verb might run into some extra meaning, but it didn’t raise any flags with the one native speaker (not Shanghainese) that I asked

I am pretty sure it is fine. Zuo is just a phonetic annotation for a variety of characters in Mandarin. And I don’t think people would think in their own dialects when they see zuo in the first place. 99% of Chinese dialects don’t have romanization systems. The only exceptions that come to my mind are Wu Chinese and Cantonese, and yet I don’t think their counterparts for pinyin are widely used.

My point is that no Chinese think in Pinyin, even though we use it daily nowadays when we are typing. So zuo
should be :100: fine

The word “zuo” (“作”) is now widely used on the Chinese internet. It indeed has a bit of negative connotations (see https://en.wikipedia.org/wiki/No_zuo_no_die), if you use it alone (or slang). But for programmers, no one cares about the negative connotations. They just think the name is interesting. I agree with @capfredf. No reason to change the name, unless you’d like to give it a Hanzi, e.g. “作”. That might be a bit weird.

Ok - thanks @capfredf and @chansey97