I had intended to get into the stylesheet question as my next Glk project. However, it occurs to me that none of the libraries I support have sound. So I can toss in new APIs without doing any hard work.
By the same token, I don’t exactly know what the implementation issues are. So I’ll start with some questions.
My plan is to add two Glk calls:
schanid_t glk_schannel_create_ext(glui32 rock, glui32 volume);
This is just like glk_schannel_create(), except you can specify a start volume other than the default 0x10000. I don’t anticipate any implementation problems with this.
void glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, glui32 duration, glui32 notify);
If duration and notify are zero, this is just like glk_schannel_set_volume().
If the duration is nonzero, the volume change occurs smoothly over the given number of milliseconds. (Specify 1000 for a one-second volume change.)
If the notify flag is nonzero, you’ll get an evtype_VolumeNotify when the volume change is complete (or shortly thereafter, since Glk events err on the side of late).
At most one volume change can be occurring on a sound channel at any time. If you call a volume-setting function while a previous volume change is in progress, the previous change is interrupted.
Open questions, for people who support sound-capable Glk libraries:
First, is this volume change stuff viable? (Both on the OS side and on the libmodplug side.) It’s clearly what audio I7 extensions need to stop being hacked-up monstrosities – no offense to Damusix, but there’s no good way to do volume changes now, and this would permit it. If it can actually be implemented.
If you interrupt a volume change, can I specify that the new volume change starts at wherever the volume was where it was interrupted? Can you implement that? The other options are to leave the behavior unspecified, or specify that the volume jumps to the end of the interrupted volume change before starting its new change. The latter is mandating clicks, and the former leaves the possibility of clicks open (which means authors have to avoid the whole situation).
Are there any libraries that support sound but don’t support sound notification events? I’d like to tighten that up, and say that notification events (sound and volume) are a mandatory feature rather than optional. This would make I7 extension code much simpler.
EDIT-ADD: I also considered an API call for “destroy this sound channel, after reducing the volume to zero over N milliseconds”. Clearly this isn’t necessary; you can make it happen using a volume change with notification. However, it might be convenient. If not all libraries wind up supporting volume notifications, it might be necessary after all. But maybe those libraries couldn’t provide the feature at all?