Music!

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

User avatar
Ice Cream Jonsey
Posts: 28925
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Music!

Post by Ice Cream Jonsey »

Is there code out there to play a random song and then, when it's finished, play a different song? I never figured out how to do it in Necrotic Drift, but I imagine that it's possible.

And if this is in the release Future Boy! source, I apologize. I'm checking that tonight.
the dark and gritty...Ice Cream Jonsey!

Merk
Posts: 192
Joined: Mon Nov 22, 2004 3:19 pm
Location: Wichita, KS
Contact:

Post by Merk »

I'm not aware of a way do detect when a song ends, and assuming the player is at a prompt, there wouldn't be any way to code a new song to start until your Hugo code is called again. If I think of something, I'll post again. I'm doubtful, though.

User avatar
Ice Cream Jonsey
Posts: 28925
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Post by Ice Cream Jonsey »

inky and ctate from the ifMud got me heading down the system timer path... basically, Hugo can access the system time, so if you know the length of a piece of music you can determine when the next one should play.

I don't think that Hugo keeps track of the number of seconds since the beginning of Unix time (or even the number of seconds since you started playing the game, which would be helpful) so I think one will have to make a call for the current time and then increment to a future time that you'll check against every turn.

There's no way to start up that next piece of music until the player types something in, but that's fine for my purposes. If they aren't typing something in fairly regularly they probably aren't at the game, so no biggie.

I wrote a similar function to all of this when I was coding in C several years ago, so I guess I can re-use some of that code. (Well, I wasn't playing music thereafter, but still.) I'll package it up and release it so everyone can implement it.

(If I implement the Spellcasting interface, which I won't for a WIP, but probably will for the sake of HUMAN KNOWLEDGE) there could be a nice little framework a new coder could hopefully use and do something with. Possibilities!)
the dark and gritty...Ice Cream Jonsey!

Merk
Posts: 192
Joined: Mon Nov 22, 2004 3:19 pm
Location: Wichita, KS
Contact:

Post by Merk »

Yeah, but since the music suspends when the Hugo window loses focus, it's only going to be accurate if the user never switches windows during a game. Or is it only MIDI that gets halted until the window gets focus again? No, it's MP3's as well, I'm pretty sure, because that's what I had in Trading Punches.

A better solution would be a counter that only ticks while the window has focus, *or* a way to not pause the music when the window loses focus. I guess the worst that would happen, though, is that a song ends before it's supposed to, and a different one starts.

User avatar
Ice Cream Jonsey
Posts: 28925
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Post by Ice Cream Jonsey »

That's right. You'd have the song ending early when you went back to the game and it checked the time. "Oh!" the game would say, right before the hard-rocking part of Stairway to Heaven, "It's time for a new song!"

And then the game randomly chooses a piece of screechtronica and everyone hisses. =(

But yeah, a timer ticking while the game is active is probably the best solution.
the dark and gritty...Ice Cream Jonsey!

Merk
Posts: 192
Joined: Mon Nov 22, 2004 3:19 pm
Location: Wichita, KS
Contact:

Post by Merk »

Except that I don't think there is any way to do a timer that only runs while the window is active.

Still, you've got a better solution than no solution at all.

Kent
Posts: 119
Joined: Fri Jun 27, 2003 12:10 pm

Post by Kent »

Yeah, there's really no way to explicitly tell when a song has finished playing. Call this a shortcoming of the current implementation, and call the implementation "The thing that was easiest to do across all platforms and disparate sound/media subsystems".

A system() call could probably be implemented to return the state of media playback, and this could be wrapped in a handy library call. Man, that's a good idea.

User avatar
Ice Cream Jonsey
Posts: 28925
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Post by Ice Cream Jonsey »

Bumping this because I implemented this on Sunday. I'll attach the code and eventually upload it all to the archive as a package.
the dark and gritty...Ice Cream Jonsey!

Post Reply