fixed path to external icons
[shermanaquarium] / sherman-aquarium / shermans / soundeffects.c
1
2
3 #include "soundeffects.h"
4 #include "settings.h"
5 #include "aquarium.h"
6 #include <string.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11 #include <signal.h>
12
13 static Sound_settings sound_settings;
14
15 Sound_settings *sound_get_settings_ptr(void)
16 {
17     return &sound_settings;
18 }
19
20 static void sound_exec(char *prg, char *sound)
21 {
22     static int pid=-1;
23     char *argv[256]; 
24     int argc=0, start=0,i;
25     
26     if(pid!=-1){
27         if(kill(pid,0)==0)
28             return;
29     }
30
31     for(i=0;i<strlen(prg)+1;i++){
32         if(prg[i]==' ' || prg[i]=='\0'){
33             argv[argc]=g_malloc0(i-start);
34             strncpy(argv[argc],prg+start,i-start);
35             //printf("--argv[%d]=%s--\n",argc,argv[argc]);
36             argc++;
37             start=i+1;
38         }
39     }
40
41     argv[argc]=g_strdup_printf("%s/%s", aquarium_install_path(), sound);
42     argv[argc+1]=NULL;
43     g_spawn_async(".", argv, NULL, 
44                   G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL|G_SPAWN_SEARCH_PATH,
45                   NULL,NULL, &pid, NULL);
46
47
48     for(i=0;i<=argc;i++){
49         g_free(argv[i]);
50     }
51
52 }
53
54
55 void sound_eatscream(void)
56 {
57     AquariumData *ad;
58
59     ad = aquarium_get_settings_ptr();
60
61     if(sound_settings.on && !ad->proximity){
62         if(sound_settings.type == TYPE_MP3)
63             sound_exec(sound_settings.prg, "sounds/mp3/deathscream.mp3");
64         else
65             sound_exec(sound_settings.prg, "sounds/ogg/deathscream.ogg");
66
67     }
68 }
69
70 void sound_explode(void)
71 {
72     AquariumData *ad;
73
74     ad = aquarium_get_settings_ptr();
75
76     if(sound_settings.on  && !ad->proximity){
77         if(sound_settings.type == TYPE_MP3)
78             sound_exec(sound_settings.prg, "sounds/mp3/explode.mp3");
79         else
80             sound_exec(sound_settings.prg, "sounds/ogg/explode.ogg");
81     }
82 }
83
84 void sound_bubbles(void)
85 {
86     AquariumData *ad;
87
88     ad = aquarium_get_settings_ptr();
89     if(sound_settings.on  && !ad->proximity){
90
91         if((rand()%600)<4){
92             if((rand()%10)<4){
93                 if(sound_settings.type == TYPE_MP3)
94                     sound_exec(sound_settings.prg, "sounds/mp3/manybubbles.mp3");
95                 else
96                     sound_exec(sound_settings.prg, "sounds/ogg/manybubbles.ogg");
97             }
98             else{
99                 if(sound_settings.type == TYPE_MP3)
100                     sound_exec(sound_settings.prg, "sounds/mp3/fewbubbles.mp3");
101                 else
102                     sound_exec(sound_settings.prg, "sounds/ogg/fewbubbles.ogg");
103             }
104         }
105     }
106 }