Skip to content

Commit

Permalink
Pretracker support (#30)
Browse files Browse the repository at this point in the history
* Enable support for pretracker modules
* bump build number
* Review changes
  • Loading branch information
sitomani committed Jan 15, 2024
1 parent 7d49b2c commit 5af03b6
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 46 deletions.
16 changes: 8 additions & 8 deletions 4champ.xcodeproj/project.pbxproj
Expand Up @@ -845,7 +845,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -901,7 +901,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = NO;
NEW_SETTING = "";
SDKROOT = iphoneos;
Expand All @@ -919,7 +919,7 @@
CODE_SIGN_ENTITLEMENTS = ampplayer.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 30;
CURRENT_PROJECT_VERSION = 33;
DEVELOPMENT_TEAM = 2G92PSCBJ9;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
HEADER_SEARCH_PATHS = (
Expand All @@ -928,7 +928,7 @@
"../uade-ios/src/include",
);
INFOPLIST_FILE = "$(SRCROOT)/4champ/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -937,7 +937,7 @@
../openmpt,
"../uade-ios",
);
MARKETING_VERSION = 3.5;
MARKETING_VERSION = 3.6;
PRODUCT_BUNDLE_IDENTIFIER = com.boogiesoftware.ampplayer;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -955,7 +955,7 @@
CODE_SIGN_ENTITLEMENTS = ampplayer.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 30;
CURRENT_PROJECT_VERSION = 33;
DEVELOPMENT_TEAM = 2G92PSCBJ9;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
HEADER_SEARCH_PATHS = (
Expand All @@ -964,7 +964,7 @@
"../uade-ios/src/include",
);
INFOPLIST_FILE = "$(SRCROOT)/4champ/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -973,7 +973,7 @@
../openmpt,
"../uade-ios",
);
MARKETING_VERSION = 3.5;
MARKETING_VERSION = 3.6;
PRODUCT_BUNDLE_IDENTIFIER = com.boogiesoftware.ampplayer;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
64 changes: 37 additions & 27 deletions 4champ/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion 4champ/Replay/Hively/HVLReplayer.mm
Expand Up @@ -25,6 +25,8 @@ @implementation HVLReplayer {

int hvlStereoSeparation;
}

@synthesize name = _name;
static int iHivelyBufPos = 0;

+ (NSArray<NSString*>*)supportedFormats {
Expand All @@ -34,6 +36,7 @@ @implementation HVLReplayer {
- (HVLReplayer*) init {
self = [super init];
if (self) {
_name = @"Hively";
hvl_InitReplayer();

iHivelyBufPos = kHivelyRenderSamples;
Expand Down Expand Up @@ -201,5 +204,4 @@ - (bool) loadModule:(NSString *)path type:(NSString*) type {
return true;
}


@end
1 change: 1 addition & 0 deletions 4champ/Replay/ModulePlayer.swift
Expand Up @@ -227,6 +227,7 @@ class ModulePlayer: NSObject {
nextIndex += 1
}
if play(at: nextIndex) == false {
guard playQueue.count > nextIndex else { return }
playQueue.remove(at: nextIndex)
}
}
Expand Down
8 changes: 8 additions & 0 deletions 4champ/Replay/OpenMPT/MPTReplayer.m
Expand Up @@ -11,6 +11,7 @@
@implementation MPTReplayer {
openmpt_module* currentOMPTFile;
}
@synthesize name = _name;

+ (NSArray<NSString*>*)supportedFormats {
return @[@"669",
Expand Down Expand Up @@ -59,6 +60,12 @@ @implementation MPTReplayer {
@"PT36"];
}

- (MPTReplayer*) init {
self = [super init];
_name = @"OpenMPT";
return self;
}

- (bool) loadModule:(NSString *)path type:(NSString*)type {
NSData* data = [[NSFileManager defaultManager] contentsAtPath:path];
if (!data) return false;
Expand Down Expand Up @@ -164,4 +171,5 @@ - (NSInteger) volumeOnChannel:(NSInteger)channel {
return volInt;
}


@end
5 changes: 3 additions & 2 deletions 4champ/Replay/Replay.h
Expand Up @@ -51,8 +51,9 @@

/// Visualisation API getters
@protocol ReplayInformation <NSObject>
- (int) currentPosition; //returns current position in current module
- (int) moduleLength; //returns current mod length in seconds
@property (nonatomic, strong, readonly) NSString* name; // name of the replayer lib
- (int) currentPosition; //returns current position in current module in seconds. 0 if not known
- (int) moduleLength; //returns current mod length in seconds. 0 if not known
- (NSInteger) volumeOnChannel:(NSInteger)channel; //returns current volume on requested channel
- (NSInteger) numberOfChannels; //returns number of channels in current module
- (NSArray<NSString*>*) getSamples; //returns sample names of current mod
Expand Down
5 changes: 5 additions & 0 deletions 4champ/Replay/Replay.m
Expand Up @@ -33,6 +33,8 @@ @interface Replay () {

@implementation Replay

@synthesize name = _name;

// Static byte buffers for reading render data into
static SInt16* bufLeft;
static SInt16* bufRight;
Expand All @@ -50,6 +52,7 @@ -(id)init
self=[super init];
if (self) {
self.replayers = @[[MPTReplayer class], [HVLReplayer class], [UADEReplayer class]];
_name = @"";
}
return self;
}
Expand Down Expand Up @@ -146,6 +149,7 @@ - (bool) loadModule:(NSString *)path type:(NSString*)type
}
renderer = [[replayerClass alloc] init];
}
_name = renderer.name;
return [renderer loadModule:path type:type];
}

Expand Down Expand Up @@ -314,4 +318,5 @@ static OSStatus playbackCallback(void *inRefCon,

return noErr;
}

@end
24 changes: 23 additions & 1 deletion 4champ/Replay/UADE/UADEReplayer.m
Expand Up @@ -29,6 +29,8 @@ @implementation UADEReplayer{
int fds[2];
}

@synthesize name = _name;

+ (NSArray<NSString*>*)supportedFormats {
return @[@"AAM", // ArtAndMagic,
@"ABK", // Amos ABK
Expand Down Expand Up @@ -121,6 +123,7 @@ @implementation UADEReplayer{
@"PM40",// Promizer
@"PN", // Pokey Noise
@"POWT", @"PT", // Laxity
@"PRT", // Pretracker
@"PRU1",// ProRunner
@"PRU2",// ProRunner
@"PS", // Paul Shields
Expand Down Expand Up @@ -188,6 +191,7 @@ -(void) uadeThread:(NSArray*)params {
- (UADEReplayer*) init {
self = [super init];
if (self) {
_name = @"UADE";
NSString* bu = [NSBundle mainBundle].resourcePath;
NSString* bd = [bu stringByAppendingString:@"/Frameworks/uade_ios.framework/UADERes.bundle"];

Expand Down Expand Up @@ -328,6 +332,13 @@ - (void)setStereoSeparation:(NSInteger)value {
}

- (int)currentPosition {
if(ustate) {
const struct uade_song_info *info = uade_get_song_info(ustate);
int bytespersecond = UADE_BYTES_PER_FRAME *
uade_get_sampling_rate(ustate);
int64_t playTime = (info->subsongbytes) / bytespersecond;
return (int)playTime;
}
return 0;
}

Expand All @@ -343,6 +354,7 @@ - (int)currentPosition {

- (int)moduleLength {
if(ustate) {
const struct uade_song_info *info = uade_get_song_info(ustate);
return ustate->song.info.duration;
}
return 0;
Expand All @@ -359,7 +371,17 @@ - (NSInteger)volumeOnChannel:(NSInteger)channel {
- (int)readFrames:(size_t)count bufLeft:(int16_t *)bufLeft bufRight:(int16_t *)bufRight {
int16_t buf[count*2];
ssize_t retVal = uade_read(&buf, sizeof buf, ustate);


struct uade_notification n;
// Check for song end
if (uade_read_notification(&n, ustate)) {
bool atEnd = n.type == UADE_NOTIFICATION_SONG_END;
uade_cleanup_notification(&n);
if(atEnd) {
return 0;
}
}

if(retVal<0) {
NSLog(@"Error reading data");
return 0;
Expand Down
1 change: 1 addition & 0 deletions 4champ/Scenes/Radio/RadioInteractor.swift
Expand Up @@ -414,6 +414,7 @@ extension RadioInteractor: ModulePlayerObserver {
if let previous = previous {
addToSessionHistory(module: previous)
}
presenter?.presentReplayer(name: modulePlayer.renderer.name)
}

func statusChanged(status: PlayerStatus) {
Expand Down
3 changes: 2 additions & 1 deletion 4champ/Scenes/Radio/RadioModels.swift
Expand Up @@ -45,7 +45,8 @@ enum Radio {
}

struct ViewModel {
var timeLeft: String
var timeLeft: String?
var name: String?
}
}

Expand Down
12 changes: 10 additions & 2 deletions 4champ/Scenes/Radio/RadioPresenter.swift
Expand Up @@ -10,6 +10,7 @@ import UIKit
protocol RadioPresentationLogic {
func presentControlStatus(status: RadioStatus)
func presentChannelBuffer(buffer: [MMD], history: [MMD])
func presentReplayer(name: String)
func presentSessionHistoryInsert()
func presentPlaybackTime(length: Int, elapsed: Int)
func presentNotificationStatus(response: Radio.LocalNotifications.Response)
Expand All @@ -33,6 +34,13 @@ class RadioPresenter: RadioPresentationLogic {
}
}

func presentReplayer(name: String) {
DispatchQueue.main.async {
let vm = Radio.Playback.ViewModel(name: name)
self.viewController?.displayPlaybackInfo(viewModel: vm)
}
}

func presentChannelBuffer(buffer: [MMD], history: [MMD]) {
log.debug("")
var nextUp: String?
Expand All @@ -52,13 +60,13 @@ class RadioPresenter: RadioPresentationLogic {
}

func presentPlaybackTime(length: Int, elapsed: Int) {
let timeLeft = length - elapsed
let timeLeft = length > 0 ? length - elapsed : elapsed
let seconds = timeLeft % 60
let minutes = (timeLeft - seconds) / 60
let timeString = String.init(format: "%d:%02d", minutes, seconds)
let vm = Radio.Playback.ViewModel(timeLeft: timeString)
DispatchQueue.main.async {
self.viewController?.displayPlaybackTime(viewModel: vm)
self.viewController?.displayPlaybackInfo(viewModel: vm)
}
}

Expand Down
15 changes: 11 additions & 4 deletions 4champ/Scenes/Radio/RadioViewController.swift
Expand Up @@ -10,7 +10,7 @@ import UIKit
protocol RadioDisplayLogic: class {
func displayControlStatus(viewModel: Radio.Control.ViewModel)
func displayChannelBuffer(viewModel: Radio.ChannelBuffer.ViewModel)
func displayPlaybackTime(viewModel: Radio.Playback.ViewModel)
func displayPlaybackInfo(viewModel: Radio.Playback.ViewModel)
func displayLocalNotificationStatus(viewModel: Radio.LocalNotifications.ViewModel)
func displayNewModules(viewModel: Radio.NewModules.ViewModel)
func displaySessionHistoryInsert()
Expand All @@ -34,6 +34,7 @@ class RadioViewController: UIViewController, RadioDisplayLogic {
@IBOutlet weak var composerLabel: UILabel?
@IBOutlet weak var sizeLabel: UILabel?
@IBOutlet weak var timeLabel: UILabel?
@IBOutlet weak var playerLabel: UILabel?

@IBOutlet weak var localLabel: UILabel?
@IBOutlet weak var saveButton: UIButton?
Expand Down Expand Up @@ -238,7 +239,7 @@ class RadioViewController: UIViewController, RadioDisplayLogic {
currentModule = current
currentModuleView?.alpha = 1
composerLabel?.text = current.composer
nameLabel?.text = current.name
nameLabel?.text = "\(current.name) (\(current.type ?? ""))"
sizeLabel?.text = "\(current.size ?? 0) kb"
localLabel?.isHidden = !current.hasBeenSaved()
faveButton?.isSelected = current.favorite
Expand All @@ -262,11 +263,17 @@ class RadioViewController: UIViewController, RadioDisplayLogic {
radioTable?.reloadData()
animateGradient(.out)
historyTitle?.text = ""
playerLabel?.text = ""
}
}

func displayPlaybackTime(viewModel: Radio.Playback.ViewModel) {
timeLabel?.text = viewModel.timeLeft
func displayPlaybackInfo(viewModel: Radio.Playback.ViewModel) {
if let time = viewModel.timeLeft {
timeLabel?.text = time
}
if let replayer = viewModel.name {
playerLabel?.text = replayer
}
}

func displayLocalNotificationStatus(viewModel: Radio.LocalNotifications.ViewModel) {
Expand Down

0 comments on commit 5af03b6

Please sign in to comment.