Skip to content

Commit

Permalink
Add simple playback example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dudejoe870 committed Jul 3, 2024
1 parent 2892d65 commit 10bb65a
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 6 deletions.
16 changes: 10 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ set(GODOT_GDEXTENSION_DIR godot-cpp/gdextension/ CACHE STRING "Path to GDExtensi
set(CPP_BINDINGS_PATH godot-cpp/ CACHE STRING "Path to C++ bindings")
set(GODOT_LIB_PATH custom-godotcpp-build/bin CACHE STRING "Path to the built Godot C++ libraries")
set(GODOT_GEN_INCLUDE_PATH custom-godotcpp-build/gen/include CACHE STRING "Path to generated Godot includes")
set(EXAMPLE_DIR ${CMAKE_SOURCE_DIR}/example/ CACHE STRING "Path to example project")

# Change the output directory to the bin directory
set(BUILD_PATH ${CMAKE_SOURCE_DIR}/bin)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_PATH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BUILD_PATH}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_PATH}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")

# Set the c++ standard to c++17
set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -184,5 +185,8 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME ${MAIN_EXT_OUTPUT_NAME}
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${BUILD_PATH}/${MAIN_EXT_OUTPUT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_SOURCE_DIR}/addons/godot-openmpt/bin/${MAIN_EXT_OUTPUT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
COMMAND ${CMAKE_COMMAND} -E rm -rf ${EXAMPLE_DIR}/addons/godot-openmpt
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/addons/godot-openmpt ${EXAMPLE_DIR}/addons/godot-openmpt
DEPENDS $<TARGETFILE:${PROJECT_NAME}>
)

2 changes: 2 additions & 0 deletions example/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
3 changes: 3 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Godot 4+ specific ignores
.godot/
addons/godot-openmpt/
36 changes: 36 additions & 0 deletions example/examples/1-Simple Playback/simple_playback.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
extends Control

func _ready() -> void:
%PauseBtn.disabled = true

func _process(delta: float) -> void:
var stream_player = %AudioStreamPlayer
if stream_player.has_stream_playback():
var stream_playback = stream_player.get_stream_playback()
var current_pattern = stream_playback.get_current_pattern()
%InfoText.text = "Row: %d/%d Order: %d/%d Pattern: %d/%d" % [
stream_playback.get_current_row(),
stream_player.stream.get_pattern_num_rows(current_pattern),
stream_playback.get_current_order(),
stream_player.stream.get_num_orders(),
current_pattern,
stream_player.stream.get_num_patterns()]
else:
%InfoText.text = ""

func _on_play_btn_pressed() -> void:
%AudioStreamPlayer.play()
%PauseBtn.disabled = false
func _on_pause_btn_pressed() -> void:
%AudioStreamPlayer.stream_paused = !%AudioStreamPlayer.stream_paused
if %AudioStreamPlayer.stream_paused:
%PlayBtn.disabled = true
%StopBtn.disabled = true
%PauseBtn.text = "Unpause"
else:
%PlayBtn.disabled = false
%StopBtn.disabled = false
%PauseBtn.text = "Pause"
func _on_stop_btn_pressed() -> void:
%AudioStreamPlayer.stop()
%PauseBtn.disabled = true
57 changes: 57 additions & 0 deletions example/examples/1-Simple Playback/simple_playback.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[gd_scene load_steps=3 format=3 uid="uid://dhy0aj7k743jx"]

[ext_resource type="AudioStream" uid="uid://cje6373yknfle" path="res://examples/deusesque.xm" id="1_6yod7"]
[ext_resource type="Script" path="res://examples/1-Simple Playback/simple_playback.gd" id="1_flpse"]

[node name="SimplePlayback" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_flpse")

[node name="CenterContainer" type="CenterContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
layout_mode = 2
alignment = 1

[node name="HBoxContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer"]
layout_mode = 2
alignment = 1

[node name="PlayBtn" type="Button" parent="CenterContainer/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "Play"

[node name="PauseBtn" type="Button" parent="CenterContainer/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "Pause"

[node name="StopBtn" type="Button" parent="CenterContainer/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "Stop
"

[node name="InfoText" type="Label" parent="CenterContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2

[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
unique_name_in_owner = true
stream = ExtResource("1_6yod7")

[connection signal="pressed" from="CenterContainer/VBoxContainer/HBoxContainer/PlayBtn" to="." method="_on_play_btn_pressed"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/HBoxContainer/PauseBtn" to="." method="_on_pause_btn_pressed"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/HBoxContainer/StopBtn" to="." method="_on_stop_btn_pressed"]
Binary file added example/examples/deusesque.xm
Binary file not shown.
18 changes: 18 additions & 0 deletions example/examples/deusesque.xm.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[remap]

importer="dudejoe870.openmptimporter"
type="AudioStreamMPT"
uid="uid://cje6373yknfle"
path="res://.godot/imported/deusesque.xm-d80fe518a5e97fb7c0baab4e52327b29.res"

[deps]

source_file="res://examples/deusesque.xm"
dest_files=["res://.godot/imported/deusesque.xm-d80fe518a5e97fb7c0baab4e52327b29.res"]

[params]

force/mono=false
playback/loop_mode=1
load/skip_plugins=false
load/skip_subsongs_init=false
1 change: 1 addition & 0 deletions example/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions example/icon.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://ct0xwt4cmo8aa"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
28 changes: 28 additions & 0 deletions example/project.godot
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=5

[application]

config/name="Godot-OpenMPT-example"
run/main_scene="res://examples/1-Simple Playback/simple_playback.tscn"
config/features=PackedStringArray("4.2", "Mobile")
config/icon="res://icon.svg"

[dotnet]

project/assembly_name="Godot-OpenMPT-example"

[editor_plugins]

enabled=PackedStringArray("res://addons/godot-openmpt/plugin.cfg")

[rendering]

renderer/rendering_method="mobile"

0 comments on commit 10bb65a

Please sign in to comment.