Skip to content

Commit

Permalink
Don't allow mode switch while dragging
Browse files Browse the repository at this point in the history
Also made some edits to U/R relevant code to hopefully improve
understandability
  • Loading branch information
towai committed Aug 14, 2024
1 parent 2604093 commit 0932235
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 47 deletions.
2 changes: 1 addition & 1 deletion copy_confirm.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func _on_copy_confirmed():
Global.pasting = true
Global.pasted_selection = []
for note in Global.copy_data:
%Chart.add_note(false,note[0]+target,note[1],note[2],note[3],true)
%Chart.add_note(false,note[0]+target,note[1],note[2],note[3])
Global.pasting = false

Global.clear_future_edits()
Expand Down
7 changes: 7 additions & 0 deletions global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func time_to_beat(time:float) -> float: return time * (60.0 / working_tmb.tempo)
###Dew's globals###
var revision = -1 #unedited chart
var actions = [] #0 = add, 1 = delete, 2 = dragged, 3 = paste
enum {
ACTION_ADD,
ACTION_DELETE,
ACTION_DRAG,
ACTION_PASTE,
ACTION_NONE = -1,
}
var changes = [] #current timeline of past and future revisions in order; see below
var revision_format = [
"ADD: [*[reference, old bar value]*]",
Expand Down
8 changes: 4 additions & 4 deletions main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func _input(event):
_on_save_chart_pressed()
# If editing text, ignore shortcuts besides Ctrl+(Shift)+S
# note that, even typing into numerical SpinBoxes, you're using its own child LineEdit
if ( (get_viewport().gui_get_focus_owner() is TextEdit)
|| (get_viewport().gui_get_focus_owner() is LineEdit)):
if ((get_viewport().gui_get_focus_owner() is TextEdit)
|| (get_viewport().gui_get_focus_owner() is LineEdit)):
return
if event.keycode == KEY_SHIFT && !%PlayheadHandle.dragging:
if event.pressed:
Expand All @@ -66,11 +66,11 @@ func _input(event):
_on_paste()
if event.pressed && event.is_action_pressed("toggle_playback"):
%PreviewController._do_preview()
if event.is_action("select_mode") && !Input.is_key_pressed(KEY_CTRL):
if event.is_action("select_mode") && !Input.is_key_pressed(KEY_CTRL) && !Input.get_mouse_button_mask():
%Chart.mouse_mode = %Chart.SELECT_MODE
$Alert.alert("Switched mouse to Select Mode", Vector2(%ChartView.global_position.x, 10),
Alert.LV_SUCCESS)
if event.is_action("edit_mode") && !Input.is_key_pressed(KEY_CTRL):
if event.is_action("edit_mode") && !Input.is_key_pressed(KEY_CTRL) && !Input.get_mouse_button_mask():
%Chart.mouse_mode = %Chart.EDIT_MODE
$Alert.alert("Switched mouse to Edit Mode", Vector2(%ChartView.global_position.x, 10),
Alert.LV_SUCCESS)
Expand Down
45 changes: 25 additions & 20 deletions pianoroll/chart.gd
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,19 @@ var mouse_mode : int = EDIT_MODE
var show_preview : bool = false
var playhead_preview : float = 0.0
###Dew variables###
var rev : int #the "act" setter determines which revision is to be activated by adding 1 if redoing.
#Redoing enacts next edit in line(+1) (NOT FOR DRAGS OR PASTE), and undoing enacts current edit(+0).
#Drag edits are stored as an array containing 1-3 arrays, each subarray containing [a note's reference, its old data, its new data].
var act := -1 : #-1 = normal operation (0 = undo triggered, 1 = redo triggered)
var rev : int # the "act" setter determines which revision is to be activated by adding 1 if redoing.
# Redoing enacts next edit in line(+1) (NOT FOR DRAGS OR PASTE), and undoing enacts current edit(+0).
# Drag edits are stored as an array containing 1-3 arrays, each subarray containing [a note's reference, its old data, its new data].
var ur_type : int = UR_NONE : #-1 = normal operation (0 = undo triggered, 1 = redo triggered)
set(value):
rev = Global.revision + value
act = value
var action := -1 #initial value, set equal to Global.actions[Global.revision] on successful undo/redo input
ur_type = value
enum {
UR_NONE = -1,
UR_UNDO = 0,
UR_REDO = 1,
}
var action := Global.ACTION_NONE #initial value, set equal to Global.actions[Global.revision] on successful undo/redo input
var stuffed_note : Note #note reference waiting to be altered (stuffed with desired data) when u/r-ing a drag
enum { #enumerates the three indices of a DRAGGED note set: [note_reference, pre-drag_data, post-drag_data]
REF,
Expand Down Expand Up @@ -106,7 +111,7 @@ func _shortcut_input(event):
if Input.is_action_just_pressed("ui_undo") && !shift.shift_pressed:
print("\n",Global.revision,": undo pressed...","\n")
if Global.revision != -1: #if we're at the beginning of edit history, there are no changes to undo!
act = 0
ur_type = UR_UNDO
if Global.actions[rev] < 2: #If we aren't undoing a drag or copy-paste, we can just swap the original action taken.
action = !Global.actions[rev] #Undoing an added note(0) deletes it(1); undoing a deleted note(1) adds it back(0).
else: #Negating these manual actions keeps logic progressing forward through edit chain.
Expand All @@ -116,7 +121,7 @@ func _shortcut_input(event):
if Input.is_action_just_pressed("ui_redo"):
print("\n",Global.revision,": redo pressed...","\n")
if Global.revision < Global.actions.size()-1: #revision count is -1 indexed (0 means revision has 1 existing edit; revision = *index* of timeline action)
act = 1
ur_type = UR_REDO
action = Global.actions[rev] #redoing a manual add(0) adds the note(still 0), redoing a manual delete(1) deletes the note(still 1).
Global.revision += 1
ur_handler()
Expand All @@ -129,21 +134,20 @@ func ur_handler():
print("Selected data:", Global.changes[rev])
print("Expected format: ",Global.revision_format[action])
match action:
0: #add desired note(s)
Global.ACTION_ADD:
for note in Global.changes[rev]:
print("UR adding!")
add_child(note[REF]) #simply shows a hidden note
note[REF].bar = note[OLD]

1: #delete desired note(s)
Global.ACTION_DELETE:
for note in Global.changes[rev]:
print("UR deleting!")
clearing_notes = true
remove_child(note[REF]) #simply hides a select note
clearing_notes = false
note[REF].bar = -69420
2: #drag desired note(s)
if act == 0: #undo
Global.ACTION_DRAG:
if ur_type == UR_UNDO:
for note in Global.changes[rev]:
print("UR dragging (undo)!")
stuffed_note = note[REF]
Expand All @@ -153,25 +157,26 @@ func ur_handler():
print("UR dragging (redo)!")
stuffed_note = note[REF]
add_note(false, note[NEW][0], note[NEW][1], note[NEW][2], note[NEW][3])
3: #paste desired note(s)
var notes_new = Global.changes[rev][act]
Global.ACTION_PASTE: #paste desired note(s)
var notes_new = Global.changes[rev][ur_type]
print("URing the copypasta (replace)!")
if notes_new.size() > 0:
clearing_notes = true
for note in notes_new:
add_child(note)
print("confirm new note at bar: ",note.bar)
clearing_notes = false
act = !act
var notes_old = Global.changes[rev][act]
ur_type = !ur_type
print(ur_type)
var notes_old = Global.changes[rev][ur_type]
print("URing the copypasta (remove)!")
if notes_old.size() > 0:
clearing_notes = true
for note in notes_old:
remove_child(note)
print("removed old note at bar: ",note.bar)
clearing_notes = false
act = -1
ur_type = UR_NONE
update_note_array()
Global.in_ur = false

Expand Down Expand Up @@ -256,7 +261,7 @@ func _on_tmb_loaded():

func add_note(start_drag:bool, bar:float, length:float, pitch:float, pitch_delta:float = 0.0):
var note : Note
if act == -1: note = note_scn.instantiate()
if ur_type == UR_NONE: note = note_scn.instantiate()
else: note = stuffed_note #Dew: don't create a new note if we're mid-U/R action; we track pre-existing notes via Global.changes when we remove them.
note.bar = bar
note.length = length
Expand All @@ -268,7 +273,7 @@ func add_note(start_drag:bool, bar:float, length:float, pitch:float, pitch_delta
if doot_enabled && !Global.in_ur && !Global.pasting: doot(pitch)
if Global.in_ur && settings.length.value < tmb.get_last_note_off():
settings.length.value = max(2,ceilf(tmb.get_last_note_off()))
if act == -1: add_child(note) #Dew: We don't want to re-add the child to the parent if the data was only changed via drag; it's still on-screen.
if ur_type == UR_NONE: add_child(note) #Dew: We don't want to re-add the child to the parent if the data was only changed via drag; it's still on-screen.
else: return
note.grab_focus()

Expand Down
29 changes: 7 additions & 22 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ toggle_slide_prop={
}
toggle_snap_pitch={
"deadzone": 0.0,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":69,"unicode":101,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":80,"unicode":112,"echo":false,"script":null)
]
}
toggle_snap_time={
"deadzone": 0.0,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":84,"key_label":0,"unicode":116,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":84,"unicode":116,"echo":false,"script":null)
]
}
hold_drag_playhead={
Expand All @@ -72,7 +72,7 @@ hold_drag_playhead={
}
hold_insert_taps={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":70,"unicode":102,"echo":false,"script":null)
]
}
hold_slide_prop={
Expand All @@ -90,34 +90,19 @@ hold_snap_time={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194326,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
mode_input={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":49,"key_label":0,"unicode":49,"echo":false,"script":null)
]
}
mode_section={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":50,"echo":false,"script":null)
]
}
mode_lyrics={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"echo":false,"script":null)
]
}
lyrics_mode={
edit_mode={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":76,"unicode":108,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null)
]
}
select_mode={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
]
}
edit_mode={
lyrics_mode={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"echo":false,"script":null)
]
}

Expand Down

0 comments on commit 0932235

Please sign in to comment.