mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-09 00:13:55 +00:00
* Baystruments - I had two tgstation forks for some reason and had to delete one and that nuked the last PR (#51459) Instruments and sound channels refactor. * Baystruments - I had two tgstation forks for some reason and had to delete one and that nuked the last PR * Fixes dme dupe * Fixes dme dupe (#52954) Co-authored-by: silicons <2003111+silicons@users.noreply.github.com> Co-authored-by: AnturK <AnturK@users.noreply.github.com> Co-authored-by: Useroth <37159550+Useroth@users.noreply.github.com>
32 lines
1018 B
Plaintext
32 lines
1018 B
Plaintext
/**
|
|
* Instrument key datums contain everything needed to know how to play a specific
|
|
* note of an instrument.*
|
|
*/
|
|
/datum/instrument_key
|
|
/// The numerical key of what this is, from 1 to 127 on a standard piano keyboard.
|
|
var/key
|
|
/// The actual sample file that will be loaded when playing.
|
|
var/sample
|
|
/// The frequency to play the sample to get our desired note.
|
|
var/frequency
|
|
/// Deviation up/down from the pivot point that uses its sample. Used to calculate frequency.
|
|
var/deviation
|
|
|
|
/datum/instrument_key/New(sample = src.sample, key = src.key, deviation = src.deviation, frequency = src.frequency)
|
|
src.sample = sample
|
|
src.key = key
|
|
src.deviation = deviation
|
|
src.frequency = frequency
|
|
if(!frequency && deviation)
|
|
calculate()
|
|
|
|
/**
|
|
* Calculates and stores our deviation.
|
|
*/
|
|
/datum/instrument_key/proc/calculate()
|
|
if(!deviation)
|
|
CRASH("Invalid calculate call: No deviation or sample in instrument_key")
|
|
#define KEY_TWELTH (1/12)
|
|
frequency = 2 ** (KEY_TWELTH * deviation)
|
|
#undef KEY_TWELTH
|