Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/music.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
music.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22/* utility */
23#include "connection.h"
24#include "log.h"
25
26/* client */
27#include "audio.h"
28#include "client_main.h"
29#include "options.h"
30
31#include "music.h"
32
33/**********************************************************************/
36 void start_style_music(void)
37{
38 if (client_state() != C_S_RUNNING) {
39 /* Style music plays in running game only */
40 return;
41 }
42
43 if (client.conn.playing == NULL) {
44 /* Detached connections and global observers currently not
45 * supported */
46 return;
47 }
48
49 if (gui_options.sound_enable_game_music) {
50 struct music_style *pms;
51
52 stop_style_music();
53
54 pms = music_style_by_number(client.conn.playing->music_style);
55
56 if (pms != NULL) {
57 const char *tag = NULL;
58
59 switch (client.conn.playing->client.mood) {
60 case MOOD_COUNT:
61 fc_assert(client.conn.playing->client.mood != MOOD_COUNT);
62 fc__fallthrough; /* No break but use default tag */
63 case MOOD_PEACEFUL:
64 tag = pms->music_peaceful;
65 break;
66 case MOOD_COMBAT:
67 tag = pms->music_combat;
68 break;
69 }
70
71 if (tag != NULL && tag[0] != '\0') {
72 log_debug("Play %s", tag);
73 audio_play_music(tag, NULL, MU_INGAME);
74 }
75 }
76 }
77}
78
79/**********************************************************************/
82 void stop_style_music(void)
83{
84 audio_stop_usage();
85}
86
87/**********************************************************************/
90 void start_menu_music(const char *const tag, char *const alt_tag)
91{
92 if (gui_options.sound_enable_menu_music) {
93 audio_play_music(tag, alt_tag, MU_MENU);
94 }
95}
96
97/**********************************************************************/
100 void stop_menu_music(void)
101{
102 audio_stop_usage();
103}
104
105/**********************************************************************/
108 void play_single_track(const char *const tag)
109{
110 if (client_state() != C_S_RUNNING) {
111 /* Only in running game */
112 return;
113 }
114
115 audio_play_track(tag, NULL);
116}
117
118/**********************************************************************/
121 void musicspec_reread_callback(struct option *poption)
122{
123 const char *musicset_name = option_str_get(poption);
124
125 audio_restart(sound_set_name, musicset_name);
126
127 /* Start suitable music from the new set */
128 if (client_state() != C_S_RUNNING) {
129 start_menu_music("music_menu", NULL);
130 } else {
131 start_style_music();
132 }
133}
audio_restart
void audio_restart(const char *soundset_name, const char *musicset_name)
Definition audio.c:369
audio_play_track
void audio_play_track(const char *const tag, char *const alt_tag)
Definition audio.c:577
audio_play_music
void audio_play_music(const char *const tag, char *const alt_tag, enum music_usage usage)
Definition audio.c:566
audio_stop_usage
void audio_stop_usage(void)
Definition audio.c:602
audio.h
MU_INGAME
@ MU_INGAME
Definition audio.h:43
MU_MENU
@ MU_MENU
Definition audio.h:43
client
struct civclient client
Definition client_main.c:149
client_state
enum client_states client_state(void)
Definition client_main.c:1029
sound_set_name
char sound_set_name[512]
Definition client_main.c:138
client_main.h
C_S_RUNNING
@ C_S_RUNNING
Definition client_main.h:47
connection.h
log.h
fc_assert
#define fc_assert(condition)
Definition log.h:176
log_debug
#define log_debug(message,...)
Definition log.h:115
play_single_track
void play_single_track(const char *const tag)
Definition music.c:108
musicspec_reread_callback
void musicspec_reread_callback(struct option *poption)
Definition music.c:121
start_menu_music
void start_menu_music(const char *const tag, char *const alt_tag)
Definition music.c:90
stop_menu_music
void stop_menu_music(void)
Definition music.c:100
start_style_music
void start_style_music(void)
Definition music.c:36
stop_style_music
void stop_style_music(void)
Definition music.c:82
music.h
option_str_get
const char * option_str_get(const struct option *poption)
Definition options.c:868
gui_options
struct client_options gui_options
Definition options.c:71
options.h
civclient::conn
struct connection conn
Definition client_main.h:96
client_options::sound_enable_menu_music
bool sound_enable_menu_music
Definition options.h:181
client_options::sound_enable_game_music
bool sound_enable_game_music
Definition options.h:182
connection::playing
struct player * playing
Definition connection.h:156
music_style
Definition style.h:29
music_style::music_peaceful
char music_peaceful[MAX_LEN_NAME]
Definition style.h:31
music_style::music_combat
char music_combat[MAX_LEN_NAME]
Definition style.h:32
option
Definition options.c:454
player::client
struct player::@69::@72 client
player::mood
enum mood_type mood
Definition player.h:361
player::music_style
int music_style
Definition player.h:280
music_style_by_number
struct music_style * music_style_by_number(int id)
Definition style.c:171
fc__fallthrough
#define fc__fallthrough
Definition support.h:109