Freeciv-3.2
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
34struct musicset {
37 char *summary;
39} current_ms = { .summary = NULL, .description = NULL };
40
41/**********************************************************************/
45{
46 if (client_state() != C_S_RUNNING) {
47 /* Style music plays in running game only */
48 return;
49 }
50
51 if (client.conn.playing == NULL) {
52 /* Detached connections and global observers currently not
53 * supported */
54 return;
55 }
56
58 struct music_style *pms;
59
61
63
64 if (pms != NULL) {
65 const char *tag = NULL;
66
67 switch (client.conn.playing->client.mood) {
68 case MOOD_COUNT:
70 fc__fallthrough; /* No break but use default tag */
71 case MOOD_PEACEFUL:
72 tag = pms->music_peaceful;
73 break;
74 case MOOD_COMBAT:
75 tag = pms->music_combat;
76 break;
77 }
78
79 if (tag != NULL && tag[0] != '\0') {
80 log_debug("Play %s", tag);
82 }
83 }
84 }
85}
86
87/**********************************************************************/
91{
93}
94
95/**********************************************************************/
98void start_menu_music(const char *const tag, char *const alt_tag)
99{
102 }
103}
104
105/**********************************************************************/
109{
111}
112
113/**********************************************************************/
116void play_single_track(const char *const tag)
117{
118 if (client_state() != C_S_RUNNING) {
119 /* Only in running game */
120 return;
121 }
122
124}
125
126/**********************************************************************/
130{
131 const char *musicset_name = option_str_get(poption);
132
134
135 /* Start suitable music from the new set */
136 if (client_state() != C_S_RUNNING) {
137 start_menu_music("music_menu", NULL);
138 } else {
140 }
141}
142
143/**********************************************************************/
149{
151
152 if (tagfile != NULL) {
153 const char *mstr;
154
155 mstr = secfile_lookup_str(tagfile, "musicspec.name");
156
157 if (mstr == NULL) {
158 log_error(_("Musicset from %s has no name defined!"), ms_filename);
160
161 return NULL;
162 }
163
164 /* Musicset name found */
166
167 mstr = secfile_lookup_str_default(tagfile, "", "musicspec.version");
168 if (mstr[0] != '\0') {
169 /* Musicset version found */
171 } else {
172 /* No version information */
173 current_ms.version[0] = '\0';
174 }
175
176 mstr = secfile_lookup_str_default(tagfile, "", "musicspec.summary");
177 if (mstr[0] != '\0') {
178 size_t len;
179
180 /* Musicset summary found */
181 len = strlen(mstr);
184 } else {
185 /* No summary */
186 if (current_ms.summary != NULL) {
189 }
190 }
191
192 mstr = secfile_lookup_str_default(tagfile, "", "musicspec.description");
193 if (mstr[0] != '\0') {
194 size_t len;
195
196 /* Musicset description found */
197 len = strlen(mstr);
200 } else {
201 /* No Description */
202 if (current_ms.description != NULL) {
205 }
206 }
207 }
208
209 return tagfile;
210}
211
212/**********************************************************************/
230
231/**********************************************************************/
234const char *current_musicset_name(void)
235{
236 return current_ms.name;
237}
238
239/**********************************************************************/
243{
244 if (current_ms.version[0] == '\0') {
245 return NULL;
246 }
247
248 return current_ms.version;
249}
250
251/**********************************************************************/
255{
256 return current_ms.summary;
257}
258
259/**********************************************************************/
263{
264 return current_ms.description;
265}
void audio_restart(const char *soundset_name, const char *musicset_name)
Definition audio.c:376
void audio_play_track(const char *const tag, char *const alt_tag)
Definition audio.c:589
void audio_play_music(const char *const tag, char *const alt_tag, enum music_usage usage)
Definition audio.c:578
void audio_stop_usage(void)
Definition audio.c:630
@ MU_INGAME
Definition audio.h:46
@ MU_MENU
Definition audio.h:46
struct civclient client
enum client_states client_state(void)
char sound_set_name[512]
@ C_S_RUNNING
Definition client_main.h:47
char * incite_cost
Definition comments.c:75
#define MAX_LEN_NAME
Definition fc_types.h:66
#define _(String)
Definition fcintl.h:67
#define fc_assert(condition)
Definition log.h:176
#define log_debug(message,...)
Definition log.h:115
#define log_error(message,...)
Definition log.h:103
#define fc_malloc(sz)
Definition mem.h:34
void play_single_track(const char *const tag)
Definition music.c:116
void musicspec_reread_callback(struct option *poption)
Definition music.c:129
const char * current_musicset_version(void)
Definition music.c:242
const char * current_musicset_name(void)
Definition music.c:234
struct musicset current_ms
void start_menu_music(const char *const tag, char *const alt_tag)
Definition music.c:98
const char * current_musicset_summary(void)
Definition music.c:254
const char * current_musicset_description(void)
Definition music.c:262
void stop_menu_music(void)
Definition music.c:108
struct section_file * musicspec_load(const char *ms_filename)
Definition music.c:148
void start_style_music(void)
Definition music.c:44
void stop_style_music(void)
Definition music.c:90
void musicspec_close(struct section_file *tagfile)
Definition music.c:219
const char * option_str_get(const struct option *poption)
Definition options.c:893
struct client_options gui_options
Definition options.c:71
int len
Definition packhand.c:127
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
Definition registry.c:50
void secfile_destroy(struct section_file *secfile)
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
struct connection conn
Definition client_main.h:96
bool sound_enable_menu_music
Definition options.h:188
bool sound_enable_game_music
Definition options.h:189
struct player * playing
Definition connection.h:151
char name[MAX_LEN_NAME]
Definition music.c:35
char version[MAX_LEN_NAME]
Definition music.c:36
char * summary
Definition music.c:37
char * description
Definition music.c:38
struct player::@70::@73 client
enum mood_type mood
Definition player.h:359
int music_style
Definition player.h:278
struct music_style * music_style_by_number(int id)
Definition style.c:171
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:791
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define fc__fallthrough
Definition support.h:119