-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Music functionality #598
Changes from 28 commits
9626a95
c1967a7
0bd367b
410492c
9ab739b
a67a6e0
c35da7d
3819c2b
06d55d2
097c336
25c8fef
aaaeed6
7aa2ddb
e3b5447
3957e01
3c2b703
5ae06cd
e66ad53
fb596b6
9615d2b
924d38c
6258a15
e22e983
befaa7d
45bded6
4bcec6c
f527625
75b2f06
cf6bc98
f0f5f71
d437beb
c4c2add
2f42698
d87b29f
29c0d88
309d43d
de10876
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class CfgFunctions | ||
{ | ||
class CBA | ||
{ | ||
class Music | ||
{ | ||
// CBA_fnc_getMusicPath | ||
class getMusicPath | ||
{ | ||
description = "Get the config path of given music class"; | ||
file = "\x\cba\addons\music\fnc_getMusicPath.sqf"; | ||
}; | ||
// CBA_fnc_getMusicData | ||
class getMusicData | ||
{ | ||
description = "Get data attached to music class"; | ||
file = "\x\cba\addons\music\fnc_getMusicData.sqf"; | ||
}; | ||
// CBA_fnc_findMusic | ||
class findMusic | ||
{ | ||
description = "Find music of spesified type"; | ||
file = "\x\cba\addons\music\fnc_findMusic.sqf"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is missing. Add the file, or remove the class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
}; | ||
// CBA_fnc_compileMusic | ||
class compileMusic | ||
{ | ||
description = "Find all music in game"; | ||
file = "\x\cba\addons\music\fnc_compileMusic.sqf"; | ||
}; | ||
// CBA_fnc_getMusicPlaying | ||
class getMusicPlaying | ||
{ | ||
description = "Returns the data on currently playing music"; | ||
file = "\x\cba\addons\music\fnc_getMusicPlaying.sqf"; | ||
}; | ||
// CBA_fnc_playMusic | ||
class playMusic | ||
{ | ||
description = "Play a given track"; | ||
file = "\x\cba\addons\music\fnc_playMusic.sqf"; | ||
}; | ||
// CBA_fnc_stopMusic | ||
class stopMusic | ||
{ | ||
description = "Stops the music playing"; | ||
file = "\x\cba\addons\music\fnc_stopMusic.sqf"; | ||
}; | ||
}; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class CfgMusic | ||
{ | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "script_component.hpp" | ||
|
||
class CfgPatches { | ||
class ADDON { | ||
author = "$STR_CBA_Author"; | ||
name = CSTRING(component); | ||
url = "$STR_CBA_URL"; | ||
units[] = {}; | ||
requiredVersion = REQUIRED_VERSION; | ||
requiredAddons[] = {"CBA_common"}; | ||
version = VERSION; | ||
authors[] = {"Fishy"}; | ||
}; | ||
}; | ||
|
||
#include "CfgFunctions.hpp" | ||
#include "CfgMusic.hpp" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_compileMusic | ||
|
||
Description: | ||
A function used to gather a list of all usable music. | ||
|
||
Parameters: | ||
none | ||
|
||
Returns: | ||
Array of compiled music | ||
|
||
Example: | ||
(begin example) | ||
_allMusic = [] call CBA_fnc_compileMusic | ||
(end example) | ||
|
||
Author: | ||
Fishy | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
if (isNil QGVARMAIN(compiledMusic)) then { | ||
private "_config"; | ||
_config = configFile >> 'CfgMusic'; | ||
private "_missionConfig"; | ||
_missionConfig = missionConfigFile >> 'CfgMusic'; | ||
private "_unsortedSongs"; | ||
_unsortedSongs = []; | ||
|
||
for [{_i=0}, {_i < (count _config)}, {INC(_i)}] do { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are only using _i to select from _missionConfig. So a forEach should work here as well shouldn't it? |
||
private "_song"; | ||
_song = _config select _i; | ||
private "_songDuration"; | ||
_songDuration = getNumber (_song >> 'duration'); | ||
if (_songDuration > 0) then { | ||
_unsortedSongs pushBack (configName _song); | ||
}; | ||
}; | ||
|
||
for [{_i=0}, {_i < (count _missionConfig)}, {INC(_i)}] do { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filtering via
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's better by a mile |
||
private "_song"; | ||
_song = _missionConfig select _i; | ||
private "_songDuration"; | ||
_songDuration = getNumber (_song >> 'duration'); | ||
if (_songDuration > 0) then { | ||
_unsortedSongs pushBack (configName _song); | ||
}; | ||
}; | ||
|
||
GVARMAIN(compiledMusic) = _unsortedSongs; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this value can contain double entries. (same name inside missionconfig and config) |
||
}; | ||
|
||
GVARMAIN(compiledMusic) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_getMusicData | ||
|
||
Description: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Header is missing some line-breaks see this as example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general this file could use some more line-breaks |
||
A function used to return data from the given music class | ||
|
||
Parameters: | ||
one string OR one config path, and a data type (eg 'name') | ||
|
||
Returns: | ||
data entry for requested music class | ||
|
||
Example: | ||
(begin example) | ||
_musicName = ["LeadTrack01_F_Bootcamp","Duration"] call CBA_fnc_getMusicData; | ||
(end example) | ||
|
||
Author: | ||
Fishy | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
params [["_className",""],["_dataType","name"]]; | ||
private "_config"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can change this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Nil would get past IS_CONFIG so I'll leave it be. |
||
|
||
if (IS_STRING(_classname)) then { | ||
//Is a string, get config | ||
_config = [_className] call CBA_fnc_getMusicPath; | ||
} else { | ||
if (IS_CONFIG(_className)) then { | ||
_config = _className; | ||
}; | ||
}; | ||
|
||
if (!IS_CONFIG(_config)) exitWith {ERROR_1("Config not found",_className);}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
//Now we have a config, grab the data | ||
[_config,_dataType,nil] call BIS_fnc_returnConfigEntry |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_getMusicPath | ||
|
||
Description: | ||
A function used to return the config path of a music file | ||
|
||
Parameters: | ||
STRING- name of track | ||
|
||
Returns: | ||
config entry of given track | ||
|
||
Example: | ||
(begin example) | ||
_configPath = ["LeadTrack01_F_Bootcamp"] call CBA_fnc_getMusicPath | ||
(end example) | ||
|
||
Authors: | ||
Fishy, Dorbedo | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
if (!params [["_className","",[""]]]) exitWith {WARNING('No classname was provided');}; | ||
|
||
private "_config"; | ||
_config = configFile >> 'CfgMusic' >> _className; | ||
private "_duration"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This use of private is even worse than private ARRAY :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll get it right eventually ;) |
||
_duration = getNumber (_config >> "duration"); | ||
|
||
if (_duration == 0) then { | ||
_config = missionConfigFile >> "CfgMusic" >> _className; | ||
_duration = getNumber (_config >> "name"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (_duration == 0) exitWith {WARNING_1("No path found for class",_className);nil}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
}; | ||
|
||
_config |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_getMusicPlaying | ||
|
||
Description: | ||
A function used to return the current time on playing music. Must have been started with CBA_fnc_playMusic | ||
|
||
Parameters: | ||
BOOL: if true, return bool (default: false) | ||
|
||
Returns: | ||
array [class, music time, time left] OR bool (true for playing music) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd personally prefer if there was There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that makes more sense |
||
|
||
Example: | ||
(begin example) | ||
_musicTime = [] call CBA_fnc_getMusicPlaying; | ||
(end example) | ||
|
||
Author: | ||
Fishy | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
if (!params [["_bool",false,[false]]]) exitWith {WARNING('Incorrect param');}; | ||
|
||
if (isNil QGVAR(track)) exitWith { | ||
if (_bool) then {false} else {['', 0, 0, 0]} | ||
}; | ||
|
||
if (_bool) exitWith {true}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be done without
and then without the |
||
|
||
GVAR(track) params ["_class","_startTime","_playPos","_duration"]; | ||
private "_trackTime"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again that weird private thingy. I won't mention it anymore for the rest of the files. |
||
_trackTime = (CBA_missionTime - _startTime) + _playPos; | ||
private "_remainingTime"; | ||
_remainingTime = _duration - _trackTime; | ||
if (_remainingTime <=0) then { | ||
_remainingTime = 0; | ||
_trackTime = 0; | ||
_class = ""; | ||
GVAR(track) = nil; | ||
}; | ||
|
||
[_class, _trackTime, _remainingTime] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_playMusic | ||
|
||
Description: | ||
A function used to play music. | ||
|
||
Parameters: | ||
1: CLASS Class to play | ||
2: INT Position to play from (default: 0) | ||
3: BOOL allowed to interupt already playing music (default: true) | ||
|
||
Returns: | ||
BOOL -true if started playing music | ||
|
||
Example: | ||
(begin example) | ||
_bool = ["LeadTrack01_F_Bootcamp", 30, true] call CBA_fnc_playMusic; | ||
(end example) | ||
|
||
|
||
Author: | ||
Fishy | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
params [["_className","",[""]],["_time",0,[0]],["_overWrite", true,[true]]]; | ||
|
||
if (_className isEqualTo "") exitWith { | ||
WARNING("No class given"); | ||
false | ||
}; | ||
|
||
If ((!_overWrite)&&{[true] call CBA_fnc_getMusicPlaying}) exitWith {false}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think |
||
|
||
private "_return"; | ||
_return = false; | ||
|
||
private "_duration"; | ||
_duration = [_className,"duration"] call CBA_fnc_getMusicData; | ||
|
||
if (!isNil "_duration") then { | ||
if (_time < _duration) then { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could make this an exitWith instead of a then. That way you could completly remove the _return variable and just return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style question. Both methods have their downsides. This is fine too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or just use |
||
playMusic [_className, _time]; | ||
GVAR(track) = [_className,CBA_missionTime,_time,_duration]; | ||
_return = true; | ||
} else { | ||
WARNING("Time is greater than song length"); | ||
}; | ||
} else { | ||
WARNING("Music not found"); | ||
}; | ||
|
||
_return |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_stopMusic | ||
|
||
Description: | ||
A function used to stop any music playing. Must have been started with CBA_fnc_playMusic, otherwise it is ignored. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the header needs an update due to changed behavior. |
||
|
||
Parameters: | ||
none | ||
|
||
Returns: | ||
BOOL: true if music was stopped, false if already stopped | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is no need to return anymore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This return value is useless as it doesn't return false anymore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions that "do stuff" as opposed to setter functions report usually nothing / |
||
|
||
Example: | ||
(begin example) | ||
_bool = call CBA_fnc_stopMusic; | ||
(end example) | ||
|
||
Author: | ||
Fishy | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
|
||
if (!([true] call CBA_fnc_getMusicPlaying)) exitWith {false}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could leave out this line. |
||
|
||
playMusic ["",0]; | ||
GVAR(track) = nil; | ||
true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disagree. No function should end with an assignment operator. At least return _a = call {
_b = 1;
}; > _a = call {
_b = 1;
nil
}; >no error, _a is undefined. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#define COMPONENT music | ||
#include "\x\cba\addons\main\script_mod.hpp" | ||
|
||
|
||
#define DEBUG_MODE_FULL | ||
#define DEFAULT_SONG_TYPE "song" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this macro isn't used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's used once in fnc_findMusic.sqf which I missed out when I uploaded! |
||
#include "\x\cba\addons\main\script_macros.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"specific" (or "specified")