soegaard2
2022-2-19 10:10:50

@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/


massung
2022-2-19 15:21:45

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?


laurent.orseau
2022-2-19 15:24:44

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


soegaard2
2022-2-19 15:25:09

@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).


laurent.orseau
2022-2-19 15:26:19

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


massung
2022-2-19 15:26:47

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.


massung
2022-2-19 15:27:14

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


soegaard2
2022-2-19 15:30:20

@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?


laurent.orseau
2022-2-19 15:31:07

#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)


massung
2022-2-19 15:32:07

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:


massung
2022-2-19 15:33:03

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



massung
2022-2-19 15:33:43

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


soegaard2
2022-2-19 15:37:12

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:


soegaard2
2022-2-19 15:37:40

Maybe two sound effects at once?


laurent.orseau
2022-2-19 15:38:30

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


laurent.orseau
2022-2-19 15:38:42

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


massung
2022-2-19 15:40:33

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:


massung
2022-2-19 15:40:57

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


massung
2022-2-19 15:42:33

Sometimes I forget I don’t have to define a derived class to use a derived class. :wink:

Thanks for the reminder!


soegaard2
2022-2-19 15:42:44

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


soegaard2
2022-2-19 15:43:13

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


massung
2022-2-19 15:43:45

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.


massung
2022-2-19 15:44:31

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


laurent.orseau
2022-2-19 15:46:09

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)


soegaard2
2022-2-19 15:46:42

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.


soegaard2
2022-2-19 16:19:32

@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 ]


massung
2022-2-19 16:40:29

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


soegaard2
2022-2-19 16:42:39

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


soegaard2
2022-2-19 16:43:15

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


massung
2022-2-19 16:43:39

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


greg
2022-2-19 16:45:48

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


soegaard2
2022-2-19 16:48:01

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.



soegaard2
2022-2-19 16:49:08

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


soegaard2
2022-2-19 16:49:37

greg
2022-2-19 16:50:32

Thanks. :smile:


ryanc
2022-2-19 19:00:54

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.


soegaard2
2022-2-19 19:16:58

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


mflatt
2022-2-19 20:10:03

@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


capfredf
2022-2-20 02:16:19

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.


capfredf
2022-2-20 02:30:59

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


chansey97
2022-2-20 03:02:17

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.


mflatt
2022-2-20 03:10:24

Ok - thanks @capfredf and @chansey97