Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add General MIDI Support #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ tyrian.sav

# Doxygen output
/doc/doxygen/

tyrian2000
.vscode
vcpkg_installed/
.DS_Store
98 changes: 89 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,48 @@

ifneq ($(filter Msys Cygwin, $(shell uname -o)), )
PLATFORM := WIN32
OS := win
TYRIAN_DIR = C:\\TYRIAN
else ifeq (Darwin, $(shell uname)) # macOS
PLATFORM := UNIX
OS := osx
TYRIAN_DIR = $(gamesdir)/opentyrian2000
else
PLATFORM := UNIX
OS := linux
TYRIAN_DIR = $(gamesdir)/opentyrian2000
endif

# detect the architecture
HOST_TRIPLET := $(shell $(CC) -dumpmachine)
_ARCH := $(word 1, $(subst -, ,$(HOST_TRIPLET)))

ifeq ($(_ARCH), aarch64)
ARCH := arm64
else
ARCH := $(_ARCH)
endif

# check if VCPKG_TRIPLET, VCPKG_TARGET_TRIPLET, or VCPKG_DEFAULT_TRIPLET is set
# if not, set it to the OS and ARCH
ifneq ($(VCPKG_TRIPLET), )
$(info VCPKG_TRIPLET: $(VCPKG_TRIPLET))
else ifneq ($(VCPKG_TARGET_TRIPLET), )
VCPKG_TRIPLET := $(VCPKG_TARGET_TRIPLET)
else ifneq ($(VCPKG_DEFAULT_TRIPLET), )
VCPKG_TRIPLET := $(VCPKG_DEFAULT_TRIPLET)
else
_VCPKG_TRIPLET := $(ARCH)-$(OS)
# if using windows, use the static-md triplet by default
ifeq ($(OS), win)
VCPKG_TRIPLET := $(_VCPKG_TRIPLET)-static-md
else
VCPKG_TRIPLET := $(_VCPKG_TRIPLET)
endif
endif

WITH_NETWORK := true
WITH_MIDI := true

################################################################################

Expand Down Expand Up @@ -56,6 +91,14 @@ ifeq ($(WITH_NETWORK), true)
EXTRA_CPPFLAGS += -DWITH_NETWORK
endif

ifeq ($(WITH_MIDI), true)
EXTRA_CPPFLAGS += -DWITH_MIDI
endif

ifeq ($(OS), linux)
EXTRA_CPPFLAGS += -DNO_NATIVE_MIDI
endif

OPENTYRIAN_VERSION := $(shell $(VCS_IDREV) 2>/dev/null && \
touch src/opentyrian_version.h)
ifneq ($(OPENTYRIAN_VERSION), )
Expand All @@ -67,20 +110,57 @@ CPPFLAGS += -DNDEBUG
CFLAGS ?= -pedantic \
-Wall \
-Wextra \
-Wno-format-truncation \
-Wno-strict-prototypes \
-Wno-missing-field-initializers \
-O2
-O3

LDFLAGS ?=
LDLIBS ?=

ifeq ($(WITH_NETWORK), true)
SDL_CPPFLAGS := $(shell $(PKG_CONFIG) sdl2 SDL2_net --cflags)
SDL_LDFLAGS := $(shell $(PKG_CONFIG) sdl2 SDL2_net --libs-only-L --libs-only-other)
SDL_LDLIBS := $(shell $(PKG_CONFIG) sdl2 SDL2_net --libs-only-l)
libmidiconv_PC_PATH :=

# check if the "vcpkg_installed" directory exists in the directory that this makefile is in
# if it does, add it to the pkg-config search path=
VCPKG_CHLDDIR := $(VCPKG_TRIPLET)/lib/pkgconfig
ifeq ($(findstring debug, $(MAKECMDGOALS)), debug)
VCPKG_CHLDDIR := $(VCPKG_TRIPLET)/debug/lib/pkgconfig
endif

# local vcpkg
ifneq ($(wildcard vcpkg_installed), )
VCPKG_PC_PATH := $(CURDIR)/vcpkg_installed/$(VCPKG_CHLDDIR)
# global vcpkg
else ifneq ($(VCPKG_ROOT), )
VCPKG_PC_PATH := $(VCPKG_ROOT)/installed/$(VCPKG_CHLDDIR)
endif

ifeq ($(PKG_CONFIG_PATH), )
PKG_CONFIG_PATH := $(VCPKG_PC_PATH):$(libmidiconv_PC_PATH):$(shell $(PKG_CONFIG) --variable pc_path pkg-config)
else
SDL_CPPFLAGS := $(shell $(PKG_CONFIG) sdl2 --cflags)
SDL_LDFLAGS := $(shell $(PKG_CONFIG) sdl2 --libs-only-L --libs-only-other)
SDL_LDLIBS := $(shell $(PKG_CONFIG) sdl2 --libs-only-l)
PKG_CONFIG_PATH := $(VCPKG_PC_PATH):$(libmidiconv_PC_PATH):$(PKG_CONFIG_PATH)
endif


SDL_PACKAGES := sdl2
MIDIPROC_LIBS :=
PC_CMD := PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG)

ifeq ($(WITH_NETWORK), true)
SDL_PACKAGES += SDL2_net
endif

ifeq ($(WITH_MIDI), true)
SDL_PACKAGES += SDL2_mixer_ext
MIDIPROC_LIBS := midiproc fluidsynth
endif

SDL_CPPFLAGS := $(shell $(PC_CMD) $(SDL_PACKAGES) $(MIDIPROC_LIBS) --cflags)
SDL_LDFLAGS := $(shell $(PC_CMD) $(SDL_PACKAGES) $(MIDIPROC_LIBS) --libs-only-L --libs-only-other)
SDL_LDLIBS := $(shell $(PC_CMD) $(SDL_PACKAGES) $(MIDIPROC_LIBS) --libs-only-l)

# add stdc++ to the ldlibs if using midiproc
ifneq ($(MIDIPROC_LIBS), )
SDL_LDLIBS += -lstdc++
endif

ALL_CPPFLAGS = -DTARGET_$(PLATFORM) \
Expand Down
25 changes: 25 additions & 0 deletions ports/midiproc/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO nikitalita/midiproc
REF "${VERSION}"
SHA512 aa885281d92197f68cc12d1b61d2b37f6860f6d54b8e3ed9a6eb6b1d805ccdb0d497f790be76e0482c348961e20550d8cc1979cc574f3a3863dfa7228265c333
HEAD_REF master
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
)

vcpkg_cmake_install()
vcpkg_cmake_config_fixup(
PACKAGE_NAME midiproc
CONFIG_PATH lib/cmake/midiproc)

vcpkg_fixup_pkgconfig()

vcpkg_copy_pdbs()

file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/share"
"${CURRENT_PACKAGES_DIR}/debug/include"
)
32 changes: 32 additions & 0 deletions ports/midiproc/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "midiproc",
"version": "0.1.0",
"description": "MIDI processing library",
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"features": {
"test": {
"description": "Enable tests",
"dependencies": [
{
"name": "sdl2",
"host": true
},
{
"name": "sdl2-mixer-ext",
"features": ["fluidsynth"]
}
]
}
},
"default-features": []
}
30 changes: 30 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,29 @@ bool load_opentyrian_config(void)
}
}
}
section = config_find_section(config, "music", NULL);
if (section != NULL)
{
const char *music_device_name;
const char *soundfont_name;

if (config_get_string_option(section, "music_device", &music_device_name))
{
for (size_t i = 0; i < COUNTOF(music_device_names); ++i)
{
if (strcmp(music_device_name, music_device_names[i]) == 0)
{
music_device = i;
break;
}
}
}

if (config_get_string_option(section, "soundfont", &soundfont_name))
strncpy(soundfont, soundfont_name, MAX(strlen(soundfont_name) + 1, 4096));


}

fclose(file);

Expand Down Expand Up @@ -327,6 +350,13 @@ bool save_opentyrian_config(void)
for (size_t i = 0; i < COUNTOF(mouseSettings); ++i)
config_set_string_option(section, mouseSettingNames[i], mouseSettingValues[mouseSettings[i] - 1]);

section = config_find_or_add_section(config, "music", NULL);
if (section == NULL)
exit(EXIT_FAILURE); // out of memory

config_set_string_option(section, "music_device", music_device_names[music_device]);
config_set_string_option(section, "soundfont", soundfont);

FILE *file = dir_fopen(get_user_directory(), "opentyrian.cfg", "w");
if (file == NULL)
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/helptext.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void read_encrypted_pascal_string(char *s, size_t size, FILE *f)

decrypt_string(buffer, len);

assert(len < size);
//assert(len < size);

len = MIN(len, size - 1);
memcpy(s, buffer, len);
Expand Down
Loading