Sound patch

The place to discuss creating, porting and modifying Celestia's source code.
chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 9 months
Location: Seattle, Washington, USA

Post #61by chris » 05.09.2006, 17:33

hank wrote:
ANDREA wrote:Thank you hank, but I don't use celx, only .cel files.
Yes, I thought so. My purpose was to encourage you to consider using it. You would probably find it useful in many other ways.

Another advantage of CELX is that, once loadlib is enabled, the sound patch could be implemented with a Lua add-on, and would not require a patched version of the Celestia code.

- Hank


Hank,

What would it take to enable loadlib? This really seems like the ideal way to add sound support to Celestia.

--Chris

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #62by Vincent » 05.09.2006, 19:38

Andrea,

Just in case you really didn't see/read my reply to your demand ( that you can find 6 posts above in this same thread), here's a copy below. It should help you to easily fade the sound in/out using a .celx script, and gives you a clue of how to include your .cel script lines into the body of a .celx script...

****************************************
Andrea, Chuft-Captain,

Of course, I had already thought about adding the fade in/out functions to the sound patch code. However, even if that would be quite easy, I didn't go further on this because I realized I simply could do it using .celx scripts...
Here are 2 short examples (copy/paste and save as fade_test1.celx, fade_test2.celx). Note that the second script, which is a tiny bit more complicated, allows to fade the sound in/out very easily with a simple line : fade_in (duration) or fade_out (duration)

- first script :

Code: Select all

-- Initialize channel 0
celestia:play ( 0, 0 ,1 ,"music.wav", 1 )
wait (2)

-- Fade the sound in on channel 0
for i = 0, 1, 0.005 do
   celestia:play ( 0, i )
   wait (0.05)
end

-- Play the sound on channel 0
celestia:play ( 0, 1 )
wait (5)

-- Fade the sound out on channel 0
for i = 1, 0, -0.005 do
   celestia:play ( 0, i )
   wait (0.05)
end

-- Stop playing sounds on channel 0
celestia:play ( 0, -1, 0, "" )



- Second script :

Code: Select all

-- Fade in function
function fade_in(duration)
   step = 0.05 / duration
   for i = 0, 1, step do
      celestia:play ( 0, i )
      wait (0.05)
   end
end

 -- Fade out function
function fade_out(duration)
   step = 0.05 / duration
   for i = 1, 0, -step do
      celestia:play ( 0, i )
      wait (0.05)
   end
end

-- Initialize channel 0
celestia:play ( 0, 0 ,1 ,"music.wav", 1 )
wait (2)

-- Fade the sound in during 5 seconds ( = duration )
fade_in (5)

-- Play the sound on channel 0
celestia:play ( 0, 1 )
wait (5)

-- Fade the sound out during 10 seconds ( = duration )
fade_out (10)

-- Stop playing sounds on channel 0.
celestia:play ( 0, -1, 0, "" )


We can also imagine more complex fade in/out functions adding start/end volumes as arguments...

Finally, if using .celx script represents a problem for you, you can just include your .cel script lines inside the .celx script body :

Code: Select all

function CEL(source)
   local script = celestia:createcelscript(source)
   while script:tick() do
      wait(0)
   end
end

CEL([[
{

# Paste here your .cel script lines

}
]])


I Hope this will solve your problem.
Last edited by Vincent on 05.09.2006, 20:47, edited 3 times in total.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
fsgregs
Posts: 1307
Joined: 07.10.2002
With us: 22 years 1 month
Location: Manassas, VA

Post #63by fsgregs » 05.09.2006, 20:40

Hi Vincent:

Thanks for the guidance in fade-in and out. If I understand correctly, scripts 1 and 2 are actually commands that can be plugged into a .cel script. If you want them in a celx script, you have to use the "function CEL(source) " commands at the bottom of your post. Did I get that right ... or am I still confused????

If I am right, can the same lines be used directly in a celx script, or must I always use the function CEL(source) command?

Frank

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 9 months
Location: Seattle, WA USA

Post #64by hank » 05.09.2006, 20:54

chris wrote:What would it take to enable loadlib? This really seems like the ideal way to add sound support to Celestia.

Enabling loadlib is a Lua build option. Currently Celestia is linking pre-built Lua libraries which do not have loadlib enabled, so we would need to rebuild the Lua libraries to enable loadlib in them.

However, it's not difficult to include the code for loadlib in celx.cpp (which I've done for testing). Here's the code I've been using for loadlib (on MacOS X):

Code: Select all

// ==================== loadlib =====================================================
/*
* This is an implementation of loadlib based on the dlfcn interface.
* The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
* NetBSD, AIX 4.2, HPUX 11, and  probably most other Unix flavors, at least
* as an emulation layer on top of native functions.
*/

extern "C" {
#include <lualib.h>
/* #include <lauxlib.h> -- don't have it */
#include <dlfcn.h>
}

static int loadlib(lua_State *L)
{
/* temp -- don't have lauxlib
 const char *path=luaL_checkstring(L,1);
 const char *init=luaL_checkstring(L,2);
*/

 const char *path=lua_tostring(L,1);
 const char *init=lua_tostring(L,2);

 void *lib=dlopen(path,RTLD_NOW);
 if (lib!=NULL)
 {
  lua_CFunction f=(lua_CFunction) dlsym(lib,init);
  if (f!=NULL)
  {
   lua_pushlightuserdata(L,lib);
   lua_pushcclosure(L,f,1);
   return 1;
  }
 }
 /* else return appropriate error messages */
 lua_pushnil(L);
 lua_pushstring(L,dlerror());
 lua_pushstring(L,(lib!=NULL) ? "init" : "open");
 if (lib!=NULL) dlclose(lib);
 return 3;
}

// ==================== loadlib =====================================================

In addition to the code above, you'd need to add:

Code: Select all

    lua_pushstring(state, "loadlib");
    lua_pushcfunction(state, loadlib);
    lua_settable(state, LUA_GLOBALSINDEX);

in order make the loadlib C function accessible to Lua scripts. I've put this code in LuaState::init for testing purposes, but it probably should go in LuaState::requestIO and LuaState::charEntered (or a common function called from them) where luaopen_io (lua_iolibopen) is called. It would be very helpful if a call to luaopen_debug was also included there.

Once, this is done, a CELX script can call loadlib to load a dynamic library. But loadlib requires a full (platform-dependent) pathname, so it shouldn't be called directly. Instead, a Lua module should be used to do the loading. Then the script can use the "require" function to load the library for access from Lua. For example, the following code uses the SPICE library:

Code: Select all

require "spicelib";

spicelib.ldpool ( "/.../naif0007.tls" );
spicelib.spklef ( "/.../vg2_jup.bsp" );
   
et = spicelib.str2et("1979 AUG 5 02:03:48.482");
x,y,z = spicelib.spkezr( "voyager 2", et,"j2000","NONE","jupiter");


In this example, the require function loads "spicelib.lua", which locates and loads the dynamic library. The Lua loader module looks like this:

Code: Select all

-- spicelib.lua

local opendylib = function(libmain)
   local pkgname = _REQUIREDNAME
   local sourceinfo = debug.getinfo(2,"S");
   local sourcefile = sourceinfo.source;
   local sourcefile = string.sub(sourcefile,2);
   local sourcedir = string.sub(sourcefile,string.find(sourcefile,".*%/"));
--[[ TO DO: handle cross-platform libraries ]]
   local libsuffix = ".dylib"
   local libfile = sourcedir..pkgname..libsuffix;
   local open_lib = loadlib(libfile,libmain);
   open_lib();
end

opendylib("luaopen_spicelib");

The loader module requires that the dynamic library have the same name and be located in the same directory. (Note that this version works only on Mac OS X because it assumes the dynamic library has a ".dylib" suffix.)

The real work, of course, is in building the dynamic library with the C code to provide a Lua binding for the library functions. Mainly this involves writing cover functions that get the arguments from the Lua stack, call the C function, and then push the results onto the Lua stack. Here's an example:

Code: Select all

static int spice_spkezr (lua_State *l)
{
    SpiceDouble state[6];
    SpiceDouble et,lt;

    checkArgs(l, 5, 5, "Four arguments expected to function spicelib.spkezr");

    const char* body    = safeGetString(l, 1, AllErrors, "First argument to spicelib.spkezr must be a string");
            et      = safeGetNumber(l, 2, AllErrors, "Second argument to spicelib.spkezr must be a string", 0.0);
    const char* frame   = safeGetString(l, 3, AllErrors, "Third argument to spicelib.spkezr must be a string");
    const char* arg4    = safeGetString(l, 4, AllErrors, "Fourth argument to spicelib.spkezr must be a string");
    const char* refbody = safeGetString(l, 5, AllErrors, "Fifth argument to spicelib.spkezr must be a string");
   
     spkezr_c ( body, et, frame, arg4, refbody, state, &lt);
     lua_pushnumber(l,state[0]);
     lua_pushnumber(l,state[1]);
     lua_pushnumber(l,state[2]);
     lua_pushnumber(l,state[3]);
     lua_pushnumber(l,state[4]);
     lua_pushnumber(l,state[5]);
     lua_pushnumber(l,lt);
   return 7;
}

I've used examples here from my experiments with using SPICE, but the same approach should work with OpenAL, etc. The important point is that, except for enabling loadlib, everything can be done externally to Celestia by a Lua add-on contributor.

- Hank

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #65by Vincent » 05.09.2006, 21:01

Hi Frank,

fsgregs wrote:If I understand correctly, scripts 1 and 2 are actually commands that can be plugged into a .cel script. If you want them in a celx script, you have to use the "function CEL(source) " commands at the bottom of your post.
Well, that's exactly the opposite. :wink: These are .celx scripts. The "function CEL(source) " commands allows you to insert .cel script lines into the body of a .celx script.

fsgregs wrote:If I am right, can the same lines be used directly in a celx script, or must I always use the function CEL(source) command?
I think you understand now these line can only be used (directly) in .celx scripts. I've suggested Andrea to do so because :
- I knew he was making a .cel script.
- Fade in/out functions can be used only in .celx script.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 5 months
Location: Rome, ITALY

Post #66by ANDREA » 05.09.2006, 22:59

Vincent wrote:Hi Frank,........I think you understand now these line can only be used (directly) in .celx scripts. I've suggested Andrea to do so because :
- I knew he was making a .cel script.
- Fade in/out functions can be used only in .celx script.

Hello Vincent, sorry for late reply, but I was trying to understand what you was saying in your first message (remember, I'm not an English speaking man, so many times I have doubts on what I'm reading). :roll:
Now I understand that this time I was right, because I understood that your script had to be inserted in a celx script, so my doubt was: what can I do with this, if I don't use celx?
Now you have explained the reason, i.e. that the fade function can be used in celx only. :cry:
Well, sorry for this, but as explained I'll make with Excel the many cel script command lines I need, obtaining about the same result.
Thanks a lot anyhow for all your messages, appreciated! :wink:
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 9 months
Location: Seattle, WA USA

Post #67by hank » 05.09.2006, 23:20

As a variation on Vincent's theme, with Lua you could define the sound functions in a library as follows:

Code: Select all

-- sound function library
sound =
{

-- init function
init = function(soundfile)
?  ? celestia:play ( 0, 0 ,1 ,soundfile, 1 )
end;

-- play function
play = function()
?  ? celestia:play ( 0, 1 )
end;

-- stop function
stop = function()
?  ? celestia:play ( 0, -1, 0, "" )
end;

-- Fade in function
fade_in = function (duration)
?  ? step = 0.05 / duration
?  ? for i = 0, 1, step do
?  ?  ?  celestia:play ( 0, i )
?  ?  ?  wait (0.05)
?  ? end
end;

? -- Fade out function
 fade_out = function(duration)
?  ? step = 0.05 / duration
?  ? for i = 1, 0, -step do
?  ?  ?  celestia:play ( 0, i )
?  ?  ?  wait (0.05)
?  ? end
end ;

}

If you put the above code in the file "sound.lua", then you could use the "sound" library functions in a CELX script as follows:

Code: Select all

require "sound";

-- Initialize 
sound.init ( "music.wav" )
wait (2)

-- Fade the sound in during 5 seconds ( = duration )
sound.fade_in (5)

-- Play the sound
sound.play ()
wait (5)

-- Fade the sound out during 10 seconds ( = duration )
sound.fade_out (10)

-- Stop playing sounds
sound.stop ()

Note that once the "sound.lua" library file is created, you can use these sound functions in any CELX script.

- Hank

Avatar
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 11 months

Post #68by Chuft-Captain » 06.09.2006, 01:22

Hank,

Just a couple of points. You've only provided the soundfile as a parameter, and you appear to have hardcoded the sound channel as channel 0, and you've also hardecoded the fade range and rate of change.

I realise you're just trying to demonstrate the principle, but it's worth pointing out that to be actually useful, the fully-fledged versions of your functions would need to parameterize all these values as well.

Regards
CC
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 22 years 9 months
Location: Seattle, WA USA

Post #69by hank » 06.09.2006, 02:45

Chuft-Captain wrote:Just a couple of points. You've only provided the soundfile as a parameter, and you appear to have hardcoded the sound channel as channel 0, and you've also hardecoded the fade range and rate of change.

I realise you're just trying to demonstrate the principle, but it's worth pointing out that to be actually useful, the fully-fledged versions of your functions would need to parameterize all these values as well.


CC,

Of course it's possible to parameterize the other values you mentioned. Whether it's necessary for the library to be useful depends on the application. If only a single sound channel and full-range fade effects are needed, then a library such as the one in my example will be effective, and the fact that it hides unneeded lower-level flexibility makes it simpler to use. More flexible (and complicated) interfaces can be defined for use in other circumstances (and the built-in CELX sound interface can always be used directly when appropriate).

Part of what I'm trying to illustrate here is precisely the use of Lua to provide customized interfaces that conceal underlying complexity. I think many people have the idea that CELX is more complicated than CEL. But the complexity of CELX can be concealed by using Lua libraries to define simplified interfaces comparable to CEL. It should be possible to define Lua functions which implement all the existing CEL commands on top of CELX, with only a slight change in syntax. That would allow the use of CEL-like syntax while enabling all the powerful features of Lua such as expressions, variables, functions, libraries, dynamic linking, etc.

- Hank

Avatar
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 11 months

Post #70by Chuft-Captain » 06.09.2006, 23:38

Thanks Hank,

I think your practice of providing simple examples is a good way for people not familiar with CelX to learn more. There's always a learning "hump" to get over with learning anything new, and examples such as this are a good way to lower the height of that hump. My comments were made not as a criticism of your example, but just in case it wasn't obvious to Andrea that your example wasn't meant to be a full solution to his original problem.

Keep them coming!

That said, not everyone has the inclination or ability to start creating LUA libraries, (even with your examples) yet many people would probably benefit as consumers of the right libaries if they were expertly written. :wink:
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

phoenix
Posts: 214
Joined: 18.06.2002
With us: 22 years 5 months
Location: Germany - Berlin

Post #71by phoenix » 15.09.2006, 17:42

the link in the original post isn't working anymore.
is there another location where I may get this patch?
most recent celestia win32-SVN-build - use at your own risk (copy over existing 1.5.1 release)

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 5 months
Location: Rome, ITALY

Post #72by ANDREA » 15.09.2006, 18:05

Vincent, after a heavy use of sounds and music in my scripts, I was wandering if there is a remote possibility for the sound patch to accept .mp3 files. 8O
I remember this has already been asked, but I see that the use of .wav files obliges to use short files, due to the bigger dimensions of wav files. This compels me to reduce the bitrate to levels that are barely sufficient for our needs, IMO.
I never can use a 192 bitrate, most of times I'm at 32 or so. :cry:
Any possibility?
Thank you for your patience. :wink:
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #73by Vincent » 15.09.2006, 19:32

phoenix wrote:the link in the original post isn't working anymore.
is there another location where I may get this patch?
phoenix,
The sound patch currently included in Celestia patch is a modified version. You can download Victor's original patch from that link : http://vincent.gian.club.fr/celestia/sound_patch.zip
Since I'm not sure Victor still wants it to be distributed, please tell me when you have it so as I can quickly remove it from my server...

ANDREA wrote:Vincent, after a heavy use of sounds and music in my scripts, I was wandering if there is a remote possibility for the sound patch to accept .mp3 files.

Andrea,
Unfortunately, OpenAL devs are not interested in including support for mp3 files since mp3 format is under a commercial license.

However, support for the Ogg Vorbis open source compressed format might be added to Celestia's sound patch. Ogg files are even smaller than mp3 files, and the quality is at least as good as with mp3 files. I don't have the time right now to make the changes myself, so if someone is interested in doing it (phoenix ? :wink: ), here is a link : http://www.xiph.org/vorbis/

[EDIT] Including support for .ogg files to a possible LUA sound feature would also be very interesting... [/EDIT]
Last edited by Vincent on 16.09.2006, 19:56, edited 2 times in total.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

phoenix
Posts: 214
Joined: 18.06.2002
With us: 22 years 5 months
Location: Germany - Berlin

Post #74by phoenix » 15.09.2006, 19:39

Vincent wrote:
phoenix wrote:the link in the original post isn't working anymore.
is there another location where I may get this patch?
phoenix,
The sound patch currently included in Celestia patch is a modified version. You can download Victor's original patch from that link : http://vincent.gian.club.fr/celestia/sound_patch.zip
Since I'm not sure Victor still want it to be distributed, please tell me when you have it so as I can quickly remove it from my server...


got it.
is there a standalone-version of your modified sound-patch?
most recent celestia win32-SVN-build - use at your own risk (copy over existing 1.5.1 release)

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #75by Vincent » 15.09.2006, 20:41

phoenix wrote:is there a standalone-version of your modified sound-patch?

I can only provide you a .txt file showing all the changes (Victor's and mines).
I'm sorry but you'll have to apply the changes manually...
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 5 months
Location: Rome, ITALY

Post #76by ANDREA » 15.09.2006, 21:09

Vincent wrote:..... Andrea,
Unfortunately, OpenAL devs are not interested in including support for mp3 files since mp3 format is under a commercial license.
However, support for the Ogg Vorbis open source compressed format might be added to Celestia's sound patch. Ogg files are even smaller than mp3 files, and the quality is at least as good as with mp3 files. I don't have the time right now to make the changes myself, so if someone is interested in doing it (phoenix ? :wink: )

Thank you Vincent, I know Ogg files, and I see that phoenix has already replied positively to your solicitation.
Many thanks to both of you :wink:
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 5 months
Location: Rome, ITALY

Post #77by ANDREA » 17.11.2006, 00:14

Vincent wrote:Ok, It's done. :) Here's the same script in .celx format :

Code: Select all

celestia:play(1, 1, 1, "music.wav", 1)
wait(1)
celestia:play(2, 1, 1, "comment.wav")
wait(50)

Hello Vincent, sorry for trouble, but I would like to add music to Harald's "The Nine Planets.celx".
I tried in many ways, but being absolutely ignorant on celx, I didn't succeed. :oops:
Will you be so kind to show me where to put your command lines?

Code: Select all

-- Example script for Lua support in celestia
-- The Nine Planets
-- (c) 2003 Harald Schmidt
-- http://www.h-schmidt.net/celestia/
-- comments, bugreports to: celestia ( at ) h-schmidt.net
-- You are free to use, copy, modify, redistribute this script,
-- but keep a credit to the original author

-- This function is called automatically when the script ends,
-- be it because it reached it's end, or the user pressed ESC:
function celestia_cleanup_callback()
  celestia:setrenderflags(orig_renderflags)
  celestia:setlabelflags(orig_labelflags)
  celestia:getobserver():singleview()
  celestia:settimescale(1.0)
  celestia:settime(orig_time + (celestia:getscripttime() / 24 / 3600) )
end

planets = {}
planets[1] = celestia:find("Mercury")
planets[2] = celestia:find("Venus")
planets[3] = celestia:find("Earth")
planets[4] = celestia:find("Mars")
planets[5] = celestia:find("Jupiter")
planets[6] = celestia:find("Saturn")
planets[7] = celestia:find("Uranus")
planets[8] = celestia:find("Neptune")
planets[9] = celestia:find("Pluto")

celestia:print("  The Nine Planets\n(preloading textures...)", 5, 0, 0, -7, -1)
wait(0.1)

for k,v in pairs(planets) do
  v:preloadtexture()
end

orig_renderflags = celestia:getrenderflags()
orig_labelflags = celestia:getlabelflags()
orig_fov = celestia:getobserver():getfov()
orig_time = celestia:gettime()

-- Try to improve performance by disabling orbits, galaxies and automag
celestia:setrenderflags{orbits=false, galaxies=false, planets=true, stars=true, labels=false, automag=false,constellations=false, markers=false, grid=false,boundaries=false}

-- disable ALL labelflags:
labelflags = celestia:getlabelflags()
for k,v in pairs(labelflags) do
  labelflags[k]=false
end
celestia:setlabelflags(labelflags)

o = celestia:getobserver()
o:singleview()
observers = celestia:getobservers()
observers[1]:splitview("h", 0.666)
wait(0.5)

observers = celestia:getobservers()
observers[1]:splitview("h", 0.5)
wait(0.5)

observers = celestia:getobservers()
for i, o in ipairs(observers) do
  o:splitview("v", 0.666)
  wait(0.5)
end

observers = celestia:getobservers()
for i = 1,3 do
  observers[i]:splitview("v", 0.5)
  wait(0.5)
end

observers = celestia:getobservers()

-- Need to resort the observer_list, because
-- I want it layed out nicely top to bottom, left to right:
observer_sort = { 3,1,2,9,7,8,6,4,5 }
obs = {}
for i = 1,9 do
  obs[observer_sort[i]] = observers[i]
end
observers = obs

-- start goto for each view, adapt distance to FOV:
for i = 1,9 do
  local fov = observers[i]:getfov()
  observers[i]:follow(planets[i])
  local vertsize = planets[i]:radius()*1.5
  -- vertsize = sin * dist
  local dist = 2*vertsize / math.sin(fov)
  observers[i]:gotodistance(planets[i], dist, 10)
end
-- wait until goto over (too lazy to use observer:travelling)
wait(10.1)

celestia:print("Accelerating time...", 6, 0, 0, -5, -2)

-- speed up time slowly
t0 = celestia:getscripttime()
repeat
  td = celestia:getscripttime() - t0
  celestia:settimescale(td*500)
  wait(0.25)
until td > 60

--reset to normal timescale:
celestia:settimescale(1)

celestia:print("Enough!", 2, 0, 0, -2, -2)

wait(2)

-- destroy layout, let earth be the only one to see:
for i = 9,1,-1 do
  if i ~= 3 then
    observers[i]:deleteview()
    wait(0.5)
  end
end

Thanks a lot, Vincent. :wink:
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #78by Vincent » 17.11.2006, 11:44

Hi Andrea,

It depends on the moment you want to start playing the sound file :

- case n?°1 : you want "mysoundfile.wav" to be played from the beginning of the script :

Code: Select all

...
celestia:print("  The Nine Planets\n(preloading textures...)", 5, 0, 0, -7, -1)
wait(0.1)

-- Play the 'music.wav' soundfile on channel 0 - loop on / nopause on
celestia:play(0, 1, 1, "mysoundfile.wav", 1)

for k,v in pairs(planets) do
  v:preloadtexture()
end
...


- case n?°2 : you want "mysoundfile.wav" to be played as soon as time is accelerated :

Code: Select all

...
celestia:print("Accelerating time...", 6, 0, 0, -5, -2)

-- Play the 'music.wav' soundfile on channel 0 - loop on / nopause on
celestia:play(0, 1, 1, "mysoundfile.wav", 1)

-- speed up time slowly
t0 = celestia:getscripttime()
...


Then, in any case, add the following line(s) both at the end of the script and in the celestia_cleanup_callback() function:

Code: Select all

...
-- destroy layout, let earth be the only one to see:
for i = 9,1,-1 do
  if i ~= 3 then
    observers[i]:deleteview()
    wait(0.5)
  end
end

-- Stop the sound playback on channel 0.
celestia:play ( 0, -1, 0, "" )

Code: Select all

...
-- This function is called automatically when the script ends,
-- be it because it reached it's end, or the user pressed ESC:
function celestia_cleanup_callback()
  celestia:setrenderflags(orig_renderflags)
  celestia:setlabelflags(orig_labelflags)
  celestia:getobserver():singleview()
  celestia:settimescale(1.0)
  celestia:settime(orig_time + (celestia:getscripttime() / 24 / 3600) )
  -- Stop the sound playback on channel 0.
  celestia:play ( 0, -1, 0, "" )
end
...


If you want the sound to be paused when the spacebar is pressed, just change the last argument from 1 to 0 in case n?°1 and/or case n?°2. Just keep in mind that the sound playback won't resume if it is paused during its second loop (known bug).
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

ANDREA
Posts: 1543
Joined: 01.06.2002
With us: 22 years 5 months
Location: Rome, ITALY

Post #79by ANDREA » 17.11.2006, 11:58

Vincent wrote:Hi Andrea, It depends on the moment you want to start playing the sound file :-.....
If you want the sound to be paused when the spacebar is pressed, just change the last argument from 1 to 0 in case n?°1 and/or case n?°2. Just keep in mind that the sound playback won't resume if it is paused during its second loop (known bug).

Thanks a lot, Vincent, very kind and precise as usual, very appreciated. :wink:
Bye

Andrea :D
"Something is always better than nothing!"
HP Omen 15-DC1040nl- Intel® Core i7 9750H, 2.6/4.5 GHz- 1TB PCIe NVMe M.2 SSD+ 1TB SATA 6 SSD- 32GB SDRAM DDR4 2666 MHz- Nvidia GeForce GTX 1660 Ti 6 GB-WIN 11 PRO

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 10 months
Location: Nancy, France

Post #80by Vincent » 17.11.2006, 14:39

You're very welcome, Andrea.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3


Return to “Development”