random music for random-docking-music

For discussion of ports to POSIX based systems, especially using GNUStep.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

random music for random-docking-music

Post by Slartibartfast »

Hello

Last night i wrote a small script, that rise the number of music-files to ... how big is your harddisk?.
!! this version works only for a lokal linux installation of Oolite


why?
random-docking-music helps when blue-danube is boring.
my script helps, if you want more ( music ).

how it works.
the script ( runner.sh / i've had no better idea for the name ) should be inserted
in the Oolite program-folder ( f.x. "/home/mattes/GNUstep/Applications/Oolite/ " ) # mattes... its me

Code: Select all

mattes@Scotty:~/GNUstep/Applications/Oolite$ ll
insgesamt 48
drwxrwxrwx 6 mattes mattes 4096 Okt 11 23:30 ./
drwxrwxrwx 3 mattes mattes 4096 Aug  9 03:02 ../
drwxrwxrwx 3 mattes mattes 4096 Okt 11 21:57 AddOns/
drwxrwxrwx 2 mattes mattes 4096 Aug  9 03:08 doc/
-rwxrwxr-x 1 mattes mattes  141 Okt 11 23:26 oolite*
drwxrwxrwx 3 mattes mattes 4096 Aug  9 03:08 oolite.app/
drwxrwxrwx 4 mattes mattes 4096 Aug  9 03:02 oolite-deps/
-rwxrwxr-x 1 mattes mattes   87 Aug  9 03:08 oolite-update*
-rw-r--r-- 1 mattes mattes   27 Aug 29  2020 release.txt
-rwxrwxr-x 1 mattes mattes 1226 Okt 11 23:10 runner.sh*
-rwxrwxr-x 1 mattes mattes 7486 Aug  9 03:08 uninstall*
mattes@Scotty:~/GNUstep/Applications/Oolite$ 
and should be started with an small entry in the oolite script ( same directory )

Code: Select all

#!/bin/sh

/home/mattes/GNUstep/Applications/Oolite/runner.sh

/home/mattes/GNUstep/Applications/Oolite/oolite.app/oolite-wrapper $@
exit $?
The script ( running.sh ) copies 8 .ogg *) files from an external directory into the music-folder
of random-docking-music.oxp ### *) the "eight" ... is adjustable
!!! in this early version 8 music files are necessary / with less -- it may crash ## again.... 8 is adjustable

if you have more than 8 music files in your external directory ( i just have 28 files )
8 of them will be randomly selected and copied to the random-docking-music folder

...then Oolite starts normal and random-docking-music plays one of these 8 songs randomly.

on the next Oolite start the formerly 8 copied music files become deleted and replaced with 8 new ones.

O.K end till now
installation .. in the next post ( one cigarette - then i'll begin writing )
the script ( with explanation ) in following post
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: random music for random-docking-music / installation

Post by Slartibartfast »

..now the installation:

1.
create a folder

Code: Select all

music4Oolite
in your home-directory " /home/mattes/music4Oolite "

2.
copy min. 8 music.ogg file into that folder (better more / with eight files - the effect is not very impressive )
btw. for converting -- an easy tool is "soundconverter" / can be installed with your paket-manager

3. edit the .js script in random-docking-music.oxp

Code: Select all

/home/mattes/GNUstep/Applications/Oolite/AddOns/RandomDockingMusic1.01.oxp/Scripts/RandomDockingMusic.js

so that it looks like this ( or use the following )
! look at the part where the .ogg are listed - this is why "eight" files are needed ( 0 .. 7 ) are eight files

Code: Select all

this.name      = "Random Docking Music"; 
this.author    = "Dennis Thony Pedersen (Frame)"; 
this.copyright = "© 2010 the Oolite team.";
this.description = "Random Docking Music script";
this.version   = "1.01";

this.startUp = function()
{
	this.musicList = new Array()
	
	this.musicList.push("rdmusic_0.ogg");
	this.musicList.push("rdmusic_1.ogg");
	this.musicList.push("rdmusic_2.ogg");
	this.musicList.push("rdmusic_3.ogg");
	this.musicList.push("rdmusic_4.ogg");
	this.musicList.push("rdmusic_5.ogg");
	this.musicList.push("rdmusic_6.ogg");
	this.musicList.push("rdmusic_7.ogg");
	
	// keep on adding or removing music in the same manner as seen above
}

this.playerStartedAutoPilot = function()
{	
 	this.OneSecTimer = new Timer(this, this.startMusic,0,1);
 	this.OneSecTimer.start();
}

this.playerCancelledAutoPilot = function(){
	
	Sound.stopMusic();
	this.OneSecTimer.stop();
	delete OneSecTimer;
	
}
 

this.startMusic = function()
{
	//is player allready docked (did he activate it just before dock)
	if(player.isDocked)
	{	
		OneSecTimer.stop();
		delete OneSecTimer;
		return;
	}
	
	//stop allready playing music if any
	
 	Sound.stopMusic()
 	
 	//select random number
 	
 	let random_number = Math.floor(this.musicList.length * Math.random());
 	log("random docking music","random number selected:"+random_number);
 	log("random docking music","now playing:"+this.musicList[random_number])
 	let track = this.musicList[random_number];
 	
 	Sound.load(track)
 	Sound.playMusic(track)
 	this.OneSecTimer.stop()
}

this.shipWillDockWithStation = function()
{	
 	Sound.stopMusic()
}
4.
copy the script runner.sh in the Oolite directory ( look at the former post )
- don't forget to make it executable ( sledgehammer: chmod 777 )

5.
edit the oolite start script (as shown in former post )

6. start Oolite ... dock/dock/dock
done

in the next post -- the script

but now a few minutes pause
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: random music for random-docking-music

Post by Slartibartfast »

hi

runner.sh

Code: Select all

#!/bin/bash
# version:  0.01  (initial )
# matthias / Slartibartfast

number_of_songs=8
copyname="rdmusic_"
music_dir="$HOME/music4Oolite"
path_2_fdmusic="$HOME""/GNUstep/Applications/Oolite/AddOns/RandomDockingMusic1.01.oxp/Music/"

#------------------------
kill_old_songs()
{
rm -f "$path_2_fdmusic""$copyname"*.ogg
}

#------------------------
make_song_array()
{
cd $music_dir
song_array=(*.ogg)
number_of_oggs=${#song_array[@]}
for (( i=0;i<$number_of_oggs;i++ ))
  do
   index_array[$i]=$i
  done
cd
}

#---------------------------------
generate_random()
{
number_of_index=${#index_array[@]}
while (( $number_of_songs < $number_of_index  )) 
 do
  random_number=$[ $RANDOM % $number_of_index ]
  unset 'index_array[$random_number]'
  declare -a reduced_index_array=()
  i=0
   for element in ${index_array[@]}
     do
      reduced_index_array[$i]=$element
      ((i++))
     done
  index_array=("${reduced_index_array[@]}")
  unset reduced_index_array
  number_of_index=${#index_array[@]}
 done
}

#-----------------------------------
copy_songs()
{
cd $music_dir
i=0
for element in ${index_array[@]}
 do
  cp "${song_array[$element]}"  "$path_2_fdmusic""$copyname"$i.ogg
  ((i++))
 done
cd
}

#---main-------
kill_old_songs
make_song_array
generate_random
copy_songs
some explanation ( even for this small one )
0. header

1. declaration of constants
see the "magical" 8 :wink: / "number_of_songs=8"

2. declaration of functions
maybe in the future the script becomes bigger / then functions keeps it clear

3. "main" --- how it runs

---------------
functions:
- kill_old_songs()
...very complicated - i don't know where to begin :roll:

- make_song_array()
reads all directory entries of .ogg in an array (the oggs you've copied in your new music folder )
counts the number of entries in that array
makes another array (index) with 0/1/2/3..... in its fields ( till it fits to first array )

- generate_random()
removes randomly one entry after the other in the index array
till the size of this array matches the "magical" 8

- copy_songs()
reads the index array and uses the "numbers inside" to specify which song
should be copied to random-docking-music music folder and .. does it
-----------------------------------------------------------------
that's it

maybe somebody likes it ( like i do )

cheers
matthias ( aka mattes/Slartibartfast )




btw:

Code: Select all

'[001] Computer World.ogg'               '01 Take Five.ogg'                                            '08 Nothing else matters.ogg'
"01 - Angel's Tear.ogg"                  '01 The Healer (With Carlos Santana & The Santana Band).ogg'  '11 Nights in white satin.ogg'
'01 Dawn, Go Within.ogg'                 '02 Radioactivity.ogg'                                        '11 Steve Ray Vaughan  Tin Pan Alley.ogg'
'01 Egyptian Danza.ogg'                  '03 Lalena.ogg'                                               '12 Cantaloop - US3.ogg'
'01 Emi Fujita  Desperado.ogg'           '04 Heart Of Gold.ogg'                                        '15 In The Air Tonight.ogg'
'01 Father Of Day, Father Of Night.ogg'  '04 Still Got the Blues.ogg'                                  '16 Jefferson Airplane - White Rabbit.ogg'
'01 Flight Over Rio.ogg'                 '04 Tears In Heaven.ogg'                                      '17 Jimi Hendrix - Little Wing.ogg'
'01 La Vie En Rose.ogg'                  '06 The Box Tops - The Letter.ogg'                             BlueDanube.ogg
'01 Smooth Operator.ogg'                 '07 Hyper-Gamma-Spaces.ogg'
'01 Space Oddity.ogg'                    '07. Samba Pa Ti.ogg'
Last edited by Slartibartfast on Wed Oct 13, 2021 2:23 pm, edited 1 time in total.
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
Cholmondely
Archivist
Archivist
Posts: 5365
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: random music for random-docking-music

Post by Cholmondely »

Aah!

If only I had some music and was running Linux!

But I can barely manage my AppleMac... It took me two months to work out where the on-off switch was!
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: random music for random-docking-music

Post by Slartibartfast »

Hello
I have made that only for myself.

If there is (more) interest - i will try to built an installer and a setup
( which makes - i think - 5 times more work than the music-installer itself )

but -- maybe one of our (admirable) OXP developers catches the idea in it
maybe - this way ( silly examples / but every user can decide about that )
docking in communist maiin-station- plays "internationale" , brecht/weil, etc.
docking on anarchie main-station -- sex pistols
docking on saloon - " one bourbon, one scotch and one beer"
......

matthias
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
Cholmondely
Archivist
Archivist
Posts: 5365
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: random music for random-docking-music

Post by Cholmondely »

I thought that Library.oxp was supposed to enable some sort of musical facility
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: random music for random-docking-music

Post by Slartibartfast »

Hello

Library.oxp
yes i have read, that it's made for things like that

But nevertheless there's one problem left.
-- importing list from outside into an *.oxp/z

In an other thread i was told, that that's not possible.

And for my idea ( therefore i made that script, which is almost
only a "workound" for that issue )
it is absout necessary to import a list from outside .oxp
( here the list is the content from a directory, that is "outside" )

Hmm..
i have problem to explain
==> example: ( from the original rdm.oxp )
this.startUp = function()
{
this.musicList = new Array()

this.musicList.push("BlueDanubeCopy.ogg");
this.musicList.push("01 - Angel's Tear.ogg");


// keep on adding or removing music in the same manner as seen above
}


must look like this:
this.startUp = function()
{
this.musicList = new Array()

"matching list with contend of the external directory"

// keep on adding or removing music in the same manner as seen above
}


and reading a directory is like reading a list.

matthias
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
hiran
Theorethicist
Posts: 2403
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: random music for random-docking-music

Post by hiran »

OXZs are packages that Oolite can load and simply use. With the current design you'd need to hack that expansion.
Your best choice is to unzip it into the Addons folder as OXP, then fiddle with whatever files you like. Actually a job for developers.

For some other usecase I verified that the javascript of some OXP/OXZ cannot access network resources. In your case that would not be necessary, but it might be worth exploring whether the javascript can access the filesystem. If that is the case I can imagine we define another folder that gets scanned by the OXP and - if found - the music gets replaced or mixed in.
Sunshine - Moonlight - Good Times - Oolite
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: random music for random-docking-music

Post by Slartibartfast »

hello
If that is the case I can imagine we define another folder that gets scanned by the OXP and - if found - the music gets replaced or mixed in.
this is the way my little bash-script works



matthias
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
User avatar
hiran
Theorethicist
Posts: 2403
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: random music for random-docking-music

Post by hiran »

Slartibartfast wrote: Tue Oct 19, 2021 1:41 pm
hello
If that is the case I can imagine we define another folder that gets scanned by the OXP and - if found - the music gets replaced or mixed in.
this is the way my little bash-script works



matthias
I get the feeling we have a lot in common :D
Sunshine - Moonlight - Good Times - Oolite
User avatar
Slartibartfast
Deadly
Deadly
Posts: 175
Joined: Mon Jan 21, 2008 3:54 pm

Re: random music for random-docking-music

Post by Slartibartfast »

Hi

meanwhile i have ~105 different "songs" for my docking computer. ( now i like the "game-pause", caused by the D.C. )
( and i have stopped importing music, because of working on "QVE-Generator" ....)

if somebody wants to use my code -- feel free to use it ...

matthias
Oolite 1.91 / Imp. Trader ( slighly modified :wink: ) on Lubuntu 22.04 LTS on AMD64 2x 3800+ ,
ATI Radeon R7240 XFS / Samsung TV 40" 1080p
C-Media CMI8738 / Yamaha RX-V575 / DIY-Speaker
Logitech Attack3 & standard german keyboard
Post Reply