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

UADE integration #17

Merged
merged 5 commits into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Integrated SamplePlayer app with uade library
  • Loading branch information
sitomani committed Oct 26, 2022
commit 9f44a5f201e4d14479f33d53cca4ca111c303989
110 changes: 56 additions & 54 deletions 4champ/Replay/UADE/UADEReplayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
#include <uade/uade.h>
#include <sys/socket.h>
#include "uae.h"

int uadeconf_loaded;
char uadeconfname[256];
enum uade_control_state ctrlstate = UADE_S_STATE;

int new_subsong = -1;
#define MAX_LEN 256
char current_format[80] = "";
#include <dirent.h>

@implementation UADEReplayer{
struct uade_config* cfg;
Expand All @@ -35,7 +28,7 @@ @implementation UADEReplayer{
char basedir[PATH_MAX];
struct uade_file* playername;
int fds[2];
}
}

+ (NSArray<NSString*>*)supportedFormats {
return @[@"AAM", // ArtAndMagic,
Expand Down Expand Up @@ -113,7 +106,7 @@ @implementation UADEReplayer{
@"MXTX",// Maxtrax
@"MCMD",// MCMD
@"MIDI",// MIDI-loriciel
@"ML", // MusicLine Editor
//@"ML",@"Ml" // MusicLine Editor - disabled since ML player does not handle file paths longer than 127 chars.
@"MOK", // Silmarilis
@"MON", // ManiacsOfNoise
@"MSO", // Medley
Expand Down Expand Up @@ -174,20 +167,20 @@ @implementation UADEReplayer{
@"WB", // Wally Beben
@"YM", // YM-2149,
@"QPA", @"SQT", @"QTS", // Quartet - PSG - ST
];
];
}

// Handle main UADE thread (amiga emu)
-(void) uadeThread:(NSArray*)params {
uadethread_running = 1;
NSLog(@"UADECore enter");
@autoreleasepool {
const char* inParam = [[params objectAtIndex:0] UTF8String];
const char* outParam = [[params objectAtIndex:1] UTF8String];

[[NSThread currentThread] setThreadPriority:0.9f];
const char *argv[5] = {"uadecore", "-i", inParam, "-o", outParam};
uadecore_main(5,(char**)argv);
const char* inParam = [[params objectAtIndex:0] UTF8String];
const char* outParam = [[params objectAtIndex:1] UTF8String];
[[NSThread currentThread] setThreadPriority:0.9f];
const char *argv[5] = {"uadecore", "-i", inParam, "-o", outParam};
uadecore_main(5,(char**)argv);
}
NSLog(@"UADECore exit");
uadethread_running=0;
Expand All @@ -196,8 +189,8 @@ -(void) uadeThread:(NSArray*)params {
- (UADEReplayer*) init {
self = [super init];
if (self) {
// get basedir from bundle
NSString *bd = [[NSBundle mainBundle] pathForResource:@"UADERes" ofType:@"bundle"];
NSBundle* uadeBundle = [NSBundle bundleWithIdentifier: @"com.apple.xcode.dsym.libuade"];
NSString *bd = [uadeBundle pathForResource:@"UADERes" ofType:@"bundle"];
strcpy(basedir, [bd UTF8String]);

struct uade_config *cfg = uade_new_config();
Expand All @@ -207,7 +200,7 @@ - (UADEReplayer*) init {
uade_config_set_option(cfg, UC_SCORE_FILE, uadescorename);
ustate = [self create_state:cfg];
free(cfg);

}
return self;
}
Expand All @@ -227,54 +220,65 @@ - (void) cleanup {
close(fds[1]);
}


/// Create UADE state. Implementation is identical with `uade_new_state` provided by libuade,
/// with the exception that uadecore is spawned in a thread, not a separate process.
/// @param extraconfig any client-specific configuration
- (struct uade_state*) create_state:(struct uade_config*)extraconfig {

struct uade_state *state;
DIR *bd;
char path[PATH_MAX];
const char *basedir;

state = calloc(1, sizeof *state);
if (!state)
return NULL;

basedir = NULL;
if (extraconfig != NULL && extraconfig->basedir_set)
basedir = extraconfig->basedir.name;

if (!uade_load_initial_config(state, basedir))
NSLog(@"uadeconfig not loaded");

if (extraconfig)
state->extraconfig = *extraconfig;
else
uade_config_set_defaults(&state->extraconfig);


if (!uade_load_initial_config(state, basedir)) {
// uade_warning("uadeconfig not loaded\n");

if (extraconfig) {
state->extraconfig = *extraconfig;
}
else {
uade_config_set_defaults(&state->extraconfig);
}
}

state->config = state->permconfig;
uade_merge_configs(&state->config, &state->extraconfig);

uade_load_initial_song_conf(state);
// load_content_db(state);

snprintf(path, sizeof path, "%s/uadecore", state->config.basedir.name);
//load_content_db(state);

bd = opendir(state->config.basedir.name);
if (bd == NULL) {
NSLog(@"Could not access dir %s", state->config.basedir.name);
return nil;
}
closedir(bd);

uade_config_set_option(&state->config, UC_UADECORE_FILE,
path);
UADE_CONFIG_UADE_CORE);

snprintf(path, sizeof path, "%s/uaerc", state->config.basedir.name);
uade_config_set_option(&state->config, UC_UAE_CONFIG_FILE, path);

uade_merge_configs(&state->config, &state->extraconfig);


/* TODO: Remove this, but make uadecore respond with a HELLO message. */
if (access(state->config.uadecore_file.name, X_OK)) {
NSLog(@"Could not execute %s", state->config.uadecore_file.name);
return nil;
}
if (access(state->config.uae_config_file.name, R_OK)) {
NSLog(@"Could not read uae config file: %s\n",
state->config.uae_config_file.name);
uade_cleanup_state(state);
return NULL;
NSLog(@"Could not read uae config file: %s", state->config.uae_config_file.name);
return nil;
}

// set up ipc
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) {
NSLog(@"Cannot create socket pair");
Expand All @@ -285,29 +289,27 @@ - (struct uade_state*) create_state:(struct uade_config*)extraconfig {
[NSThread detachNewThreadSelector:@selector(uadeThread:) toTarget:self withObject:params];

uade_set_peer(&state->ipc, 1, fds[1], fds[1]);

if (uade_send_string(UADE_COMMAND_CONFIG, state->config.uae_config_file.name, &state->ipc)) {
NSLog(@"Can not send config name: %s\n", strerror(errno));
uade_cleanup_state(state);
return NULL;
NSLog(@"Can not send config name: %s", strerror(errno));
return nil;
}

return state;

}

- (bool)loadModule:(NSString *)path type:(NSString *)type {

NSData* data = [[NSFileManager defaultManager] contentsAtPath:path];
if (!data) return false;

uade_stop(ustate);
if (!uade_is_our_file_from_buffer([path UTF8String], data.bytes, data.length, ustate)) {
NSLog(@"Not our file");
return false;
}
// uade_play([path UTF8String], 0, ustate);
// const char *fname, const void *buf, size_t size,
// int subsong, struct uade_state *state
// uade_play([path UTF8String], 0, ustate);
// const char *fname, const void *buf, size_t size,
// int subsong, struct uade_state *state
NSString* nameOnly = [[path componentsSeparatedByString:@"/"] lastObject];
uade_play_from_buffer([path UTF8String], data.bytes, data.length, 0, ustate);

Expand Down
54 changes: 31 additions & 23 deletions SamplePlayer/SamplePlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
45D707E7208B7C52004CB16A /* MPTReplayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 45D707DD208B7C52004CB16A /* MPTReplayer.m */; };
45D707E8208B7C52004CB16A /* Replay.m in Sources */ = {isa = PBXBuildFile; fileRef = 45D707DF208B7C52004CB16A /* Replay.m */; };
735012E028EC9702003EF294 /* UADEReplayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 735012DF28EC9702003EF294 /* UADEReplayer.m */; };
73759FCA28EB271A00535F8E /* libopenmpt.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 73759FC928EB271A00535F8E /* libopenmpt.xcframework */; };
73759FCA28EB271A00535F8E /* libopenmpt.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 73759FC928EB271A00535F8E /* libopenmpt.xcframework */; settings = {ATTRIBUTES = (Required, ); }; };
73759FD028EB2B0A00535F8E /* Modules.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 73759FCF28EB2B0A00535F8E /* Modules.bundle */; };
7397C1E929092561002D5CDB /* uade_ios.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 73E345A6290595DA00B3C937 /* uade_ios.xcframework */; };
7397C1EA29092561002D5CDB /* uade_ios.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 73E345A6290595DA00B3C937 /* uade_ios.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
739D39B82652A0EC001EBC9E /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 739D39B72652A0EC001EBC9E /* libz.tbd */; };
73D4C0EF28F688E800B59CAE /* uade_ios.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 73D4C0EE28F688E800B59CAE /* uade_ios.xcframework */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
7397C1EB29092561002D5CDB /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
7397C1EA29092561002D5CDB /* uade_ios.xcframework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
45C005B1208B7B1800126E78 /* SamplePlayer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SamplePlayer.app; sourceTree = BUILT_PRODUCTS_DIR; };
45C005B4208B7B1800126E78 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -45,15 +60,15 @@
73759FC928EB271A00535F8E /* libopenmpt.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = libopenmpt.xcframework; path = ../../openmpt/libopenmpt.xcframework; sourceTree = "<group>"; };
73759FCF28EB2B0A00535F8E /* Modules.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Modules.bundle; sourceTree = "<group>"; };
739D39B72652A0EC001EBC9E /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
73D4C0EE28F688E800B59CAE /* uade_ios.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = uade_ios.xcframework; path = "../../uade-ios/uade_ios.xcframework"; sourceTree = "<group>"; };
73E345A6290595DA00B3C937 /* uade_ios.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = uade_ios.xcframework; path = "../../uade-ios/uade_ios.xcframework"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
45C005AE208B7B1800126E78 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
73D4C0EF28F688E800B59CAE /* uade_ios.xcframework in Frameworks */,
7397C1E929092561002D5CDB /* uade_ios.xcframework in Frameworks */,
73759FCA28EB271A00535F8E /* libopenmpt.xcframework in Frameworks */,
739D39B82652A0EC001EBC9E /* libz.tbd in Frameworks */,
);
Expand Down Expand Up @@ -84,7 +99,6 @@
isa = PBXGroup;
children = (
73759FCF28EB2B0A00535F8E /* Modules.bundle */,
45D707EF208B7E2A004CB16A /* Modules */,
45C005B4208B7B1800126E78 /* AppDelegate.swift */,
45C005B6208B7B1800126E78 /* ViewController.swift */,
45C005B8208B7B1800126E78 /* Main.storyboard */,
Expand Down Expand Up @@ -132,20 +146,13 @@
45D707EA208B7CEA004CB16A /* Frameworks */ = {
isa = PBXGroup;
children = (
73D4C0EE28F688E800B59CAE /* uade_ios.xcframework */,
73E345A6290595DA00B3C937 /* uade_ios.xcframework */,
73759FC928EB271A00535F8E /* libopenmpt.xcframework */,
739D39B72652A0EC001EBC9E /* libz.tbd */,
);
name = Frameworks;
sourceTree = "<group>";
};
45D707EF208B7E2A004CB16A /* Modules */ = {
isa = PBXGroup;
children = (
);
path = Modules;
sourceTree = "<group>";
};
735012DD28EC9702003EF294 /* UADE */ = {
isa = PBXGroup;
children = (
Expand All @@ -165,6 +172,7 @@
45C005AD208B7B1800126E78 /* Sources */,
45C005AE208B7B1800126E78 /* Frameworks */,
45C005AF208B7B1800126E78 /* Resources */,
7397C1EB29092561002D5CDB /* Embed Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -308,7 +316,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -359,7 +367,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
Expand All @@ -377,18 +385,18 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 2G92PSCBJ9;
HEADER_SEARCH_PATHS = (
../../uade/src/frontends/include,
"../../uade-ios/src/frontends/include",
../../openmpt/libopenmpt,
../../uade/src/include,
"../../uade-ios/src/include",
);
INFOPLIST_FILE = SamplePlayer/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
../../openmpt,
../../uade,
"../../openmpt/**",
"../../uade/**",
);
PRODUCT_BUNDLE_IDENTIFIER = com.4champ.SamplePlayer;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -408,18 +416,18 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 2G92PSCBJ9;
HEADER_SEARCH_PATHS = (
../../uade/src/frontends/include,
"../../uade-ios/src/frontends/include",
../../openmpt/libopenmpt,
../../uade/src/include,
"../../uade-ios/src/include",
);
INFOPLIST_FILE = SamplePlayer/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
../../openmpt,
../../uade,
"../../openmpt/**",
"../../uade/**",
);
PRODUCT_BUNDLE_IDENTIFIER = com.4champ.SamplePlayer;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Loading