Skip to content

Commit

Permalink
[MIRROR] Instrument editor now uses TGUI (#1446)
Browse files Browse the repository at this point in the history
* Instrument editor now uses TGUI (#81923)

## About The Pull Request

Instruments now use TGUI as their editor which is pretty cool.
It's mostly a 1:1 remake of the HTML UI except I did make a change to
make the playback options a little more compact, leaving some more space
for the editor before you have to scroll, and some other minor things
that were made to make the UI hopefully nicer to look at and mess with.

When there's a song to play - While playing, Repeat section can't be
edited

![image](https://github.com/tgstation/tgstation/assets/53777086/33f21ca3-98d8-4147-83e7-74e7611463e6)

Help section and UI when there's no song put in

![image](https://github.com/tgstation/tgstation/assets/53777086/babd30ab-9551-448b-9fe6-24e0b0535caf)

## Why It's Good For The Game

It is yet another step in finishing up
https://hackmd.io/XLt5MoRvRxuhFbwtk4VAUA?view
Instruments especially were in a poor spot because they didn't respect
things like ``IN_USE`` to not refresh if it's not the "UI" you are on,
and such.

## Changelog

:cl:
refactor: Instruments now use TGUI.
/:cl:

---------

Co-authored-by: Ghom <[email protected]>

* Instrument editor now uses TGUI

---------

Co-authored-by: John Willard <[email protected]>
Co-authored-by: Ghom <[email protected]>
  • Loading branch information
3 people authored and StealsThePRs committed Mar 15, 2024
1 parent 3bb12e3 commit ca6c828
Show file tree
Hide file tree
Showing 10 changed files with 567 additions and 286 deletions.
6 changes: 4 additions & 2 deletions code/__DEFINES/instruments.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/// Max number of playing notes per instrument.
#define CHANNELS_PER_INSTRUMENT 128

/// Minimum length a note should ever go for
#define INSTRUMENT_MIN_TOTAL_SUSTAIN 0.1
/// Maximum length a note should ever go for
#define INSTRUMENT_MAX_TOTAL_SUSTAIN (5 SECONDS)

Expand All @@ -16,8 +18,8 @@
/// Minimum volume for when the sound is considered dead.
#define INSTRUMENT_MIN_SUSTAIN_DROPOFF 0

#define SUSTAIN_LINEAR 1
#define SUSTAIN_EXPONENTIAL 2
#define SUSTAIN_LINEAR "Linear"
#define SUSTAIN_EXPONENTIAL "Exponential"

// /datum/instrument instrument_flags
#define INSTRUMENT_LEGACY (1<<0) //Legacy instrument. Implies INSTRUMENT_DO_NOT_AUTOSAMPLE
Expand Down
5 changes: 4 additions & 1 deletion code/controllers/subsystem/processing/instruments.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ PROCESSING_SUBSYSTEM_DEF(instruments)
var/static/current_instrument_channels = 0
/// Single cached list for synthesizer instrument ids, so you don't have to have a new list with every synthesizer.
var/static/list/synthesizer_instrument_ids
var/static/list/note_sustain_modes = list("Linear" = SUSTAIN_LINEAR, "Exponential" = SUSTAIN_EXPONENTIAL)
var/static/list/note_sustain_modes = list(
SUSTAIN_LINEAR,
SUSTAIN_EXPONENTIAL,
)

/datum/controller/subsystem/processing/instruments/Initialize()
initialize_instrument_data()
Expand Down
2 changes: 1 addition & 1 deletion code/datums/ai/generic/generic_behaviors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@

//just in case- it won't do anything if the instrument isn't playing
song.stop_playing()
song.ParseSong(song_lines)
song.ParseSong(new_song = song_lines)
song.repeat = 10
song.volume = song.max_volume - 10
finish_action(controller, TRUE)
Expand Down
58 changes: 25 additions & 33 deletions code/modules/instruments/items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,7 @@
user.visible_message(span_suicide("[user] begins to play 'Gloomy Sunday'! It looks like [user.p_theyre()] trying to commit suicide!"))
return BRUTELOSS

/obj/item/instrument/attack_self(mob/user)
if(!ISADVANCEDTOOLUSER(user))
to_chat(user, span_warning("You don't have the dexterity to do this!"))
return TRUE
interact(user)

/obj/item/instrument/interact(mob/user)
ui_interact(user)

/obj/item/instrument/ui_interact(mob/living/user)
if(!isliving(user) || user.stat != CONSCIOUS || (HAS_TRAIT(user, TRAIT_HANDS_BLOCKED) && !ispAI(user)))
return

user.set_machine(src)
/obj/item/instrument/ui_interact(mob/user, datum/tgui/ui)
song.ui_interact(user)

/obj/item/instrument/violin
Expand Down Expand Up @@ -130,9 +117,9 @@
. = ..()
AddElement(/datum/element/spooky)

/obj/item/instrument/trumpet/spectral/attack(mob/living/carbon/C, mob/user)
playsound (src, 'sound/runtime/instruments/trombone/En4.mid', 100,1,-1)
..()
/obj/item/instrument/trumpet/spectral/attack(mob/living/target_mob, mob/living/user, params)
playsound(src, 'sound/runtime/instruments/trombone/En4.mid', 1000, 1, -1)
return ..()

/obj/item/instrument/saxophone
name = "saxophone"
Expand All @@ -154,9 +141,9 @@
. = ..()
AddElement(/datum/element/spooky)

/obj/item/instrument/saxophone/spectral/attack(mob/living/carbon/C, mob/user)
playsound (src, 'sound/runtime/instruments/saxophone/En4.mid', 100,1,-1)
..()
/obj/item/instrument/saxophone/spectral/attack(mob/living/target_mob, mob/living/user, params)
playsound(src, 'sound/runtime/instruments/trombone/En4.mid', 1000, 1, -1)
return ..()

/obj/item/instrument/trombone
name = "trombone"
Expand All @@ -178,9 +165,9 @@
. = ..()
AddElement(/datum/element/spooky)

/obj/item/instrument/trombone/spectral/attack(mob/living/carbon/C, mob/user)
playsound (src, 'sound/runtime/instruments/trombone/Cn4.mid', 100,1,-1)
..()
/obj/item/instrument/trombone/spectral/attack(mob/living/target_mob, mob/living/user, params)
playsound(src, 'sound/runtime/instruments/trombone/Cn4.mid', 1000, 1, -1)
return ..()

/obj/item/instrument/recorder
name = "recorder"
Expand All @@ -201,19 +188,24 @@
w_class = WEIGHT_CLASS_SMALL
actions_types = list(/datum/action/item_action/instrument)

/obj/item/instrument/harmonica/proc/handle_speech(datum/source, list/speech_args)
SIGNAL_HANDLER
if(song.playing && ismob(loc))
to_chat(loc, span_warning("You stop playing the harmonica to talk..."))
song.playing = FALSE

/obj/item/instrument/harmonica/equipped(mob/M, slot)
/obj/item/instrument/harmonica/equipped(mob/user, slot, initial = FALSE)
. = ..()
RegisterSignal(M, COMSIG_MOB_SAY, PROC_REF(handle_speech))
if(!(slot & slot_flags))
return
RegisterSignal(user, COMSIG_MOB_SAY, PROC_REF(handle_speech))

/obj/item/instrument/harmonica/dropped(mob/M)
/obj/item/instrument/harmonica/dropped(mob/user, silent = FALSE)
. = ..()
UnregisterSignal(M, COMSIG_MOB_SAY)
UnregisterSignal(user, COMSIG_MOB_SAY)

/obj/item/instrument/harmonica/proc/handle_speech(datum/source, list/speech_args)
SIGNAL_HANDLER
if(!song.playing)
return
if(!ismob(loc))
CRASH("[src] was still registered to listen in on [source] but was not found to be on their mob.")
to_chat(loc, span_warning("You stop playing the harmonica to talk..."))
song.playing = FALSE

/datum/action/item_action/instrument
name = "Use Instrument"
Expand Down
6 changes: 4 additions & 2 deletions code/modules/instruments/piano_synth.dm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
stopped_playing.set_output(COMPONENT_SIGNAL)

/obj/item/circuit_component/synth/proc/import_song()
synth.song.ParseSong(song.value)
synth.song.ParseSong(new_song = song.value)

/obj/item/circuit_component/synth/proc/set_repetitions()
synth.song.set_repeats(repetitions.value)
Expand All @@ -169,7 +169,9 @@
synth.song.note_shift = clamp(note_shift.value, synth.song.note_shift_min, synth.song.note_shift_max)

/obj/item/circuit_component/synth/proc/set_sustain_mode()
synth.song.sustain_mode = SSinstruments.note_sustain_modes[sustain_mode.value]
if(!(sustain_mode.value in SSinstruments.note_sustain_modes))
return
synth.song.sustain_mode = sustain_mode.value

/obj/item/circuit_component/synth/proc/set_sustain_value()
switch(synth.song.sustain_mode)
Expand Down
26 changes: 1 addition & 25 deletions code/modules/instruments/songs/_song.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
/// Are we currently playing?
var/playing = FALSE

/// Are we currently editing?
var/editing = TRUE
/// Is the help screen open?
var/help = FALSE

/// Repeats left
var/repeat = 0
/// Maximum times we can repeat
Expand Down Expand Up @@ -107,7 +102,6 @@
var/note_shift = 0
var/note_shift_min = -100
var/note_shift_max = 100
var/can_noteshift = TRUE
/// The kind of sustain we're using
var/sustain_mode = SUSTAIN_LINEAR
/// When a note is considered dead if it is below this in volume
Expand All @@ -129,7 +123,7 @@
tempo = sanitize_tempo(tempo, TRUE)
src.parent = parent
if(instrument_ids)
allowed_instrument_ids = islist(instrument_ids)? instrument_ids : list(instrument_ids)
allowed_instrument_ids = islist(instrument_ids) ? instrument_ids : list(instrument_ids)
if(length(allowed_instrument_ids))
set_instrument(allowed_instrument_ids[1])
hearing_mobs = list()
Expand Down Expand Up @@ -217,8 +211,6 @@
delay_by = 0
current_chord = 1
music_player = user
if(ismob(music_player))
updateDialog(music_player)
START_PROCESSING(SSinstruments, src)

/**
Expand Down Expand Up @@ -328,12 +320,6 @@
/datum/song/proc/set_bpm(bpm)
tempo = sanitize_tempo(600 / bpm)

/**
* Updates the window for our users. Override down the line.
*/
/datum/song/proc/updateDialog(mob/user)
ui_interact(user)

/datum/song/process(wait)
if(!playing)
return PROCESS_KILL
Expand All @@ -359,31 +345,27 @@
/datum/song/proc/set_volume(volume)
src.volume = clamp(round(volume, 1), max(0, min_volume), min(100, max_volume))
update_sustain()
updateDialog()

/**
* Setter for setting how low the volume has to get before a note is considered "dead" and dropped
*/
/datum/song/proc/set_dropoff_volume(volume)
sustain_dropoff_volume = clamp(round(volume, 0.01), INSTRUMENT_MIN_SUSTAIN_DROPOFF, 100)
update_sustain()
updateDialog()

/**
* Setter for setting exponential falloff factor.
*/
/datum/song/proc/set_exponential_drop_rate(drop)
sustain_exponential_dropoff = clamp(round(drop, 0.00001), INSTRUMENT_EXP_FALLOFF_MIN, INSTRUMENT_EXP_FALLOFF_MAX)
update_sustain()
updateDialog()

/**
* Setter for setting linear falloff duration.
*/
/datum/song/proc/set_linear_falloff_duration(duration)
sustain_linear_duration = clamp(round(duration * 10, world.tick_lag), world.tick_lag, INSTRUMENT_MAX_TOTAL_SUSTAIN)
update_sustain()
updateDialog()

/datum/song/vv_edit_var(var_name, var_value)
. = ..()
Expand All @@ -401,9 +383,6 @@
// subtype for handheld instruments, like violin
/datum/song/handheld

/datum/song/handheld/updateDialog(mob/user)
parent.ui_interact(user || usr)

/datum/song/handheld/should_stop_playing(atom/player)
. = ..()
if(. == STOP_PLAYING || . == IGNORE_INSTRUMENT_CHECKS)
Expand All @@ -414,9 +393,6 @@
// subtype for stationary structures, like pianos
/datum/song/stationary

/datum/song/stationary/updateDialog(mob/user)
parent.ui_interact(user || usr)

/datum/song/stationary/should_stop_playing(atom/player)
. = ..()
if(. == STOP_PLAYING || . == IGNORE_INSTRUMENT_CHECKS)
Expand Down
Loading

0 comments on commit ca6c828

Please sign in to comment.