Skip to content

Commit 10bb65a

Browse files
committed
Add simple playback example
1 parent 2892d65 commit 10bb65a

10 files changed

+192
-6
lines changed

CMakeLists.txt

+10-6
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@ set(GODOT_GDEXTENSION_DIR godot-cpp/gdextension/ CACHE STRING "Path to GDExtensi
1515
set(CPP_BINDINGS_PATH godot-cpp/ CACHE STRING "Path to C++ bindings")
1616
set(GODOT_LIB_PATH custom-godotcpp-build/bin CACHE STRING "Path to the built Godot C++ libraries")
1717
set(GODOT_GEN_INCLUDE_PATH custom-godotcpp-build/gen/include CACHE STRING "Path to generated Godot includes")
18+
set(EXAMPLE_DIR ${CMAKE_SOURCE_DIR}/example/ CACHE STRING "Path to example project")
1819

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

2223
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_PATH}")
2324
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BUILD_PATH}")
2425
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_PATH}")
25-
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
26-
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
27-
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
28-
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
29-
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
30-
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
26+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
27+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
28+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
29+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
30+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
31+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
3132

3233
# Set the c++ standard to c++17
3334
set(CMAKE_CXX_STANDARD 17)
@@ -184,5 +185,8 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME ${MAIN_EXT_OUTPUT_NAME}
184185
add_custom_command(
185186
TARGET ${PROJECT_NAME} POST_BUILD
186187
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}
188+
COMMAND ${CMAKE_COMMAND} -E rm -rf ${EXAMPLE_DIR}/addons/godot-openmpt
189+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/addons/godot-openmpt ${EXAMPLE_DIR}/addons/godot-openmpt
187190
DEPENDS $<TARGETFILE:${PROJECT_NAME}>
188191
)
192+

example/.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Normalize EOL for all files that Git considers text files.
2+
* text=auto eol=lf

example/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Godot 4+ specific ignores
2+
.godot/
3+
addons/godot-openmpt/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
extends Control
2+
3+
func _ready() -> void:
4+
%PauseBtn.disabled = true
5+
6+
func _process(delta: float) -> void:
7+
var stream_player = %AudioStreamPlayer
8+
if stream_player.has_stream_playback():
9+
var stream_playback = stream_player.get_stream_playback()
10+
var current_pattern = stream_playback.get_current_pattern()
11+
%InfoText.text = "Row: %d/%d Order: %d/%d Pattern: %d/%d" % [
12+
stream_playback.get_current_row(),
13+
stream_player.stream.get_pattern_num_rows(current_pattern),
14+
stream_playback.get_current_order(),
15+
stream_player.stream.get_num_orders(),
16+
current_pattern,
17+
stream_player.stream.get_num_patterns()]
18+
else:
19+
%InfoText.text = ""
20+
21+
func _on_play_btn_pressed() -> void:
22+
%AudioStreamPlayer.play()
23+
%PauseBtn.disabled = false
24+
func _on_pause_btn_pressed() -> void:
25+
%AudioStreamPlayer.stream_paused = !%AudioStreamPlayer.stream_paused
26+
if %AudioStreamPlayer.stream_paused:
27+
%PlayBtn.disabled = true
28+
%StopBtn.disabled = true
29+
%PauseBtn.text = "Unpause"
30+
else:
31+
%PlayBtn.disabled = false
32+
%StopBtn.disabled = false
33+
%PauseBtn.text = "Pause"
34+
func _on_stop_btn_pressed() -> void:
35+
%AudioStreamPlayer.stop()
36+
%PauseBtn.disabled = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[gd_scene load_steps=3 format=3 uid="uid://dhy0aj7k743jx"]
2+
3+
[ext_resource type="AudioStream" uid="uid://cje6373yknfle" path="res://examples/deusesque.xm" id="1_6yod7"]
4+
[ext_resource type="Script" path="res://examples/1-Simple Playback/simple_playback.gd" id="1_flpse"]
5+
6+
[node name="SimplePlayback" type="Control"]
7+
layout_mode = 3
8+
anchors_preset = 15
9+
anchor_right = 1.0
10+
anchor_bottom = 1.0
11+
grow_horizontal = 2
12+
grow_vertical = 2
13+
script = ExtResource("1_flpse")
14+
15+
[node name="CenterContainer" type="CenterContainer" parent="."]
16+
layout_mode = 1
17+
anchors_preset = 15
18+
anchor_right = 1.0
19+
anchor_bottom = 1.0
20+
grow_horizontal = 2
21+
grow_vertical = 2
22+
23+
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
24+
layout_mode = 2
25+
alignment = 1
26+
27+
[node name="HBoxContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer"]
28+
layout_mode = 2
29+
alignment = 1
30+
31+
[node name="PlayBtn" type="Button" parent="CenterContainer/VBoxContainer/HBoxContainer"]
32+
unique_name_in_owner = true
33+
layout_mode = 2
34+
text = "Play"
35+
36+
[node name="PauseBtn" type="Button" parent="CenterContainer/VBoxContainer/HBoxContainer"]
37+
unique_name_in_owner = true
38+
layout_mode = 2
39+
text = "Pause"
40+
41+
[node name="StopBtn" type="Button" parent="CenterContainer/VBoxContainer/HBoxContainer"]
42+
unique_name_in_owner = true
43+
layout_mode = 2
44+
text = "Stop
45+
"
46+
47+
[node name="InfoText" type="Label" parent="CenterContainer/VBoxContainer"]
48+
unique_name_in_owner = true
49+
layout_mode = 2
50+
51+
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
52+
unique_name_in_owner = true
53+
stream = ExtResource("1_6yod7")
54+
55+
[connection signal="pressed" from="CenterContainer/VBoxContainer/HBoxContainer/PlayBtn" to="." method="_on_play_btn_pressed"]
56+
[connection signal="pressed" from="CenterContainer/VBoxContainer/HBoxContainer/PauseBtn" to="." method="_on_pause_btn_pressed"]
57+
[connection signal="pressed" from="CenterContainer/VBoxContainer/HBoxContainer/StopBtn" to="." method="_on_stop_btn_pressed"]

example/examples/deusesque.xm

1.7 MB
Binary file not shown.

example/examples/deusesque.xm.import

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[remap]
2+
3+
importer="dudejoe870.openmptimporter"
4+
type="AudioStreamMPT"
5+
uid="uid://cje6373yknfle"
6+
path="res://.godot/imported/deusesque.xm-d80fe518a5e97fb7c0baab4e52327b29.res"
7+
8+
[deps]
9+
10+
source_file="res://examples/deusesque.xm"
11+
dest_files=["res://.godot/imported/deusesque.xm-d80fe518a5e97fb7c0baab4e52327b29.res"]
12+
13+
[params]
14+
15+
force/mono=false
16+
playback/loop_mode=1
17+
load/skip_plugins=false
18+
load/skip_subsongs_init=false

example/icon.svg

+1
Loading

example/icon.svg.import

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://ct0xwt4cmo8aa"
6+
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://icon.svg"
14+
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1
35+
svg/scale=1.0
36+
editor/scale_with_editor_scale=false
37+
editor/convert_colors_with_editor_theme=false

example/project.godot

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; Engine configuration file.
2+
; It's best edited using the editor UI and not directly,
3+
; since the parameters that go here are not all obvious.
4+
;
5+
; Format:
6+
; [section] ; section goes between []
7+
; param=value ; assign values to parameters
8+
9+
config_version=5
10+
11+
[application]
12+
13+
config/name="Godot-OpenMPT-example"
14+
run/main_scene="res://examples/1-Simple Playback/simple_playback.tscn"
15+
config/features=PackedStringArray("4.2", "Mobile")
16+
config/icon="res://icon.svg"
17+
18+
[dotnet]
19+
20+
project/assembly_name="Godot-OpenMPT-example"
21+
22+
[editor_plugins]
23+
24+
enabled=PackedStringArray("res://addons/godot-openmpt/plugin.cfg")
25+
26+
[rendering]
27+
28+
renderer/rendering_method="mobile"

0 commit comments

Comments
 (0)