Skip to content

Commit

Permalink
Basic Project System (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
IsotoxalDev authored May 30, 2022
1 parent f4674be commit 342f729
Show file tree
Hide file tree
Showing 37 changed files with 388 additions and 741 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ export_presets.cfg
# Mono-specific ignores
.mono/
data_*/

# GoDAW specific ignores
song.gd
24 changes: 24 additions & 0 deletions Editor/Scenes/Dialogues/DialogManager.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extends Control

onready var progress_dialog:WindowDialog = $ProgressDialog
onready var progress_label:Label = $ProgressDialog/VBoxContainer/Label
onready var progress_bar: ProgressBar = $ProgressDialog/VBoxContainer/ProgressBar

onready var file_dialog: FileDialog = $FileDialog
onready var documents_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOCUMENTS)

# Progress
func progress(title:String, text: String) -> ProgressBar:
progress_dialog.window_title = title
progress_label.text = text
progress_dialog.popup_centered()
return progress_bar
func hide_progress(): progress_dialog.hide()

# FileDialog
func file(title: String, mode: int, filters: Array) -> void:
file_dialog.window_title = title
file_dialog.mode = mode
file_dialog.filters = filters
file_dialog.current_dir = documents_dir
file_dialog.popup_centered()
13 changes: 13 additions & 0 deletions Editor/Scenes/Dialogues/NewSong/NewSong.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends ConfirmationDialog

signal new_project(project)

onready var project_name = $HBox/data/ProjectName
onready var project_type = $HBox/data/ProjectType

func _ready():
project_type.add_item("GUI", Project.PROJECT_TYPE.GUI)
project_type.add_item("SongScript", Project.PROJECT_TYPE.SONGSCRIPT)

func _confirmed():
emit_signal("new_project", Project.new(project_name.text, project_type.selected))
58 changes: 58 additions & 0 deletions Editor/Scenes/Dialogues/NewSong/NewSong.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://Editor/Scenes/Dialogues/NewSong/NewSong.gd" type="Script" id=1]

[node name="NewSong" type="ConfirmationDialog"]
margin_right = 420.0
margin_bottom = 120.0
rect_min_size = Vector2( 375, 70 )
window_title = "New Song"
script = ExtResource( 1 )

[node name="HBox" type="HBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 5.0
margin_top = 5.0
margin_right = -5.0
margin_bottom = -5.0
alignment = 1

[node name="Labels" type="VBoxContainer" parent="HBox"]
margin_right = 95.0
margin_bottom = 110.0
alignment = 1

[node name="ProjectName" type="Label" parent="HBox/Labels"]
margin_top = 39.0
margin_right = 95.0
margin_bottom = 53.0
text = "Project Name: "

[node name="ProjectType" type="Label" parent="HBox/Labels"]
margin_top = 57.0
margin_right = 95.0
margin_bottom = 71.0
text = "Project Type:"

[node name="data" type="VBoxContainer" parent="HBox"]
margin_left = 99.0
margin_right = 410.0
margin_bottom = 110.0
size_flags_horizontal = 3
alignment = 1

[node name="ProjectName" type="LineEdit" parent="HBox/data"]
margin_top = 31.0
margin_right = 311.0
margin_bottom = 55.0
rect_min_size = Vector2( 200, 0 )
size_flags_horizontal = 3
placeholder_text = "Name your masterpiece (maybe)"

[node name="ProjectType" type="OptionButton" parent="HBox/data"]
margin_top = 59.0
margin_right = 311.0
margin_bottom = 79.0
rect_min_size = Vector2( 200, 0 )
size_flags_horizontal = 3
33 changes: 0 additions & 33 deletions Editor/Scenes/Dialogues/TrackEditor/TrackEditor.gd

This file was deleted.

21 changes: 1 addition & 20 deletions Editor/Scenes/Dialogues/TrackEditor/TrackEditor.tscn
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Editor/Scenes/Dialogues/TrackEditor/TrackEditor.gd" type="Script" id=1]
[ext_resource path="res://Themes/Default/GoDAWTheme.tres" type="Theme" id=2]
[ext_resource path="res://Editor/Scenes/Dialogues/TrackEditor/GDScriptSyntaxHighlight.gd" type="Script" id=3]
[gd_scene format=2]

[node name="TrackEditor" type="WindowDialog"]
margin_right = 48.0
margin_bottom = 40.0
rect_min_size = Vector2( 876, 480 )
theme = ExtResource( 2 )
window_title = "Track Editor"
script = ExtResource( 1 )

[node name="HBoxContainer" type="HBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0

[node name="TextEdit" type="TextEdit" parent="HBoxContainer"]
margin_right = 876.0
margin_bottom = 480.0
size_flags_horizontal = 3
highlight_current_line = true
syntax_highlighting = true
show_line_numbers = true
draw_tabs = true
caret_blink = true

[node name="GDScriptSyntaxHighlight" type="Node" parent="HBoxContainer/TextEdit"]
script = ExtResource( 3 )

[connection signal="popup_hide" from="." to="." method="_unpopup"]
5 changes: 1 addition & 4 deletions Editor/Scenes/Instruments/InstrumentsPanel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ anchor_bottom = 1.0
margin_bottom = -3.0
custom_constants/separation = 10
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Title" type="VBoxContainer" parent="."]
margin_right = 1280.0
Expand All @@ -27,8 +24,8 @@ __meta__ = {
[node name="Label" type="Label" parent="Title"]
margin_right = 1280.0
margin_bottom = 1.0
custom_fonts/font = SubResource( 1 )
custom_colors/font_color = Color( 0.717647, 0.717647, 0.784314, 1 )
custom_fonts/font = SubResource( 1 )
text = "Instruments"
align = 1

Expand Down
85 changes: 46 additions & 39 deletions Editor/Scenes/SongEditor/SongEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,57 @@ extends VBoxContainer
signal playback_finished()
signal track_pressed (name)

const BASE_SONG_SCRIPT = """extends SongScript
func song():
track("%s", [
# Place your notes here
])
pass"""

var gui: bool = true
var track_name = preload("./TrackName.tscn")

onready var names = $TracksScroll/HBox/Names
onready var segments = $TracksScroll/HBox/SegmentScroll/VBoxContainer
onready var song_script_editor = $SongScriptEditor
onready var track_scroll = $TracksScroll
onready var sequencer = $Sequencer

# styles
# techno: Make this support different themes
var style_1 = preload("res://Themes/Default/SongButton1.tres")
var style_2 = preload("res://Themes/Default/SongButton2.tres")
var style_pressed = preload("res://Themes/Default/SongButtonPressed.tres")
onready var instrument_container = $InstrumentContainer

# Takes a Button since it conveniently sends an icon and message
# TODO: Not use button as param
func add_track(instrument: Button):
if !gui: return
var name = track_name.instance()
var segment_container = HBoxContainer.new()
name.set_instrument(instrument.icon, instrument.text, segment_container)
name.set_instrument(instrument.icon, instrument.text)
names.add_child(name)
name.connect("pressed", self, "emit_signal", ["track_pressed", instrument.text])
# if Global.segments == 0:
# Global.segments = segments.get_parent().get_size().x/25
# add_segments(segment_container, name.rect_size.y, true)

# TODO: Hacky code
var inst := GoDAW.get_instrument(instrument.text)
segment_container.add_child(inst)
$Sequencer.INSTRUMENTS[instrument.text] = inst
segments.add_child(segment_container)

#func add_segments(segment_container: HBoxContainer, size, style):
# for i in range(segment_container.get_child_count(), Global.segments):
# var segment = Button.new()
# segment.rect_min_size.x = 20
# segment.rect_min_size.y = size
# segment.focus_mode = Control.FOCUS_NONE
# segment.add_stylebox_override("disabled", style_pressed)
# if i % 4 == 0: style = !style
# segment.add_stylebox_override("normal", style_1 if style else style_2)
# segment.add_stylebox_override("hover", style_1 if style else style_2)
# segment.connect("gui_input", self, "segment_input", [segment])
# segment_container.add_child(segment)

func segment_input(event, segment: Button):
if event is InputEventMouseButton && event.is_pressed():
match event.button_index:
1:
segment.disabled = true
# if segment.get_index() != Global.segments - 1: return
# Global.segments += segments.get_parent().get_size().x/25
var style = segment.get_stylebox("normal") == style_1
# add_segments(segment.get_parent(), segment.get_size().x, segment)
3:
segment.disabled = false

func sequence():
if !gui:
var file = File.new()
var dir = Directory.new()
file.open("res://song.gd", File.WRITE)
file.store_string(song_script_editor.text)
file.close()
var song: SongScript = load("res://song.gd").new()
song.entry()
if song.sequence.tracks.size() != instrument_container.get_child_count():
sequencer.INSTRUMENTS.clear()
for instrument in instrument_container.get_children():
instrument.queue_free()
for track in song.sequence.tracks:
var inst = GoDAW.get_instrument(track.instrument)
sequencer.INSTRUMENTS[track.instrument] = inst
instrument_container.add_child(inst)
sequencer.sequence(song.sequence)

func _on_play():
sequence()
sequencer.play()

func _on_pause():
Expand All @@ -74,3 +69,15 @@ func _on_Sequencer_playback_finished():

func _on_TrackEditor_sequence_song(sequence):
sequencer.sequence(sequence)


func project_changed(project: Project):
gui = true if project.project_type == Project.PROJECT_TYPE.GUI else false
song_script_editor.visible = !gui
track_scroll.visible = gui
for name in names.get_children():
name.queue_free()
if project.song_script:
song_script_editor.text = project.song_script
else:
song_script_editor.text = BASE_SONG_SCRIPT % "Square"
32 changes: 11 additions & 21 deletions Editor/Scenes/SongEditor/SongEditor.tscn
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Editor/Scenes/SongScriptEditor/SongScriptEditor.tscn" type="PackedScene" id=1]
[ext_resource path="res://Editor/Scenes/SongEditor/SongEditor.gd" type="Script" id=2]
[ext_resource path="res://util/Sequencer/Sequencer.tscn" type="PackedScene" id=3]

Expand All @@ -8,16 +9,9 @@ anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 2 )

[node name="Label" type="Label" parent="."]
margin_right = 1280.0
margin_bottom = 14.0
text = "Untitled Song"
align = 1

[node name="Timeline" type="HBoxContainer" parent="."]
margin_top = 18.0
margin_right = 1280.0
margin_bottom = 28.0
margin_bottom = 10.0
__meta__ = {
"_edit_use_anchors_": false
}
Expand All @@ -41,9 +35,6 @@ __meta__ = {
[node name="HBoxContainer" type="HBoxContainer" parent="Timeline/Timeline"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Space2" type="Control" parent="Timeline"]
margin_left = 1275.0
Expand All @@ -52,29 +43,28 @@ margin_bottom = 10.0
rect_min_size = Vector2( 5, 0 )

[node name="TracksScroll" type="ScrollContainer" parent="."]
margin_top = 32.0
visible = false
margin_top = 14.0
margin_right = 1280.0
margin_bottom = 720.0
size_flags_vertical = 3
scroll_horizontal_enabled = false

[node name="HBox" type="HBoxContainer" parent="TracksScroll"]
margin_right = 1280.0
margin_bottom = 688.0
margin_bottom = 706.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Names" type="VBoxContainer" parent="TracksScroll/HBox"]
margin_bottom = 688.0
margin_bottom = 706.0

[node name="SegmentScroll" type="ScrollContainer" parent="TracksScroll/HBox"]
margin_left = 4.0
[node name="SongScriptEditor" parent="." instance=ExtResource( 1 )]
visible = false
margin_right = 1280.0
margin_bottom = 688.0
size_flags_horizontal = 3
scroll_vertical_enabled = false
margin_bottom = 720.0

[node name="VBoxContainer" type="VBoxContainer" parent="TracksScroll/HBox/SegmentScroll"]
[node name="InstrumentContainer" type="Node" parent="."]

[node name="Sequencer" parent="." instance=ExtResource( 3 )]

Expand Down
Loading

0 comments on commit 342f729

Please sign in to comment.