- Three source trees: core/ (shared C++ engine, moved from ios/core), app/ (Android UI), ios/app/ (iOS UI) - Android plays through core/ via JNI (EngineHost, jni_engine.cpp): the Oboe callback renders natively; the Kotlin model is mirrored as project text and applied as a diff, so playback continues through edits - The Kotlin engine moves to the unit tests as ReferenceEngine (golden reference) - Shared MasterRecorder in core/src/host, used by both apps; host_test - versions.properties: one versionName/versionCode for both platforms, continuing Android's numbering (iOS 0.6.0/11 -> 0.37.0/71) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
3.3 KiB
Plaintext
83 lines
3.3 KiB
Plaintext
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#import "SizzleSession+Record.h"
|
|
#import "SizzleSession+Internal.h"
|
|
|
|
#include <algorithm>
|
|
#include <string>
|
|
|
|
using namespace sizzle;
|
|
|
|
#include "host/MasterRecorder.hpp"
|
|
|
|
namespace {
|
|
|
|
using sizzle::host::MasterRecorder;
|
|
|
|
/// Android's take name: sizzle-yyyyMMdd-HHmmss.wav (-2, -3, ... if taken).
|
|
NSURL *finishTake(NSURL *dir, const std::string &path, int64_t startMillis) {
|
|
NSDateFormatter *df = [NSDateFormatter new];
|
|
df.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
|
|
df.dateFormat = @"yyyyMMdd-HHmmss";
|
|
NSString *base = [@"sizzle-" stringByAppendingString:[df stringFromDate:[NSDate dateWithTimeIntervalSince1970:startMillis / 1000.0]]];
|
|
NSURL *dst = [dir URLByAppendingPathComponent:[base stringByAppendingPathExtension:@"wav"]];
|
|
for (int i = 2; [NSFileManager.defaultManager fileExistsAtPath:dst.path]; ++i)
|
|
dst = [dir URLByAppendingPathComponent:[NSString stringWithFormat:@"%@-%d.wav", base, i]];
|
|
NSURL *src = [NSURL fileURLWithPath:@(path.c_str())];
|
|
return [NSFileManager.defaultManager moveItemAtURL:src toURL:dst error:nil] ? dst : nil;
|
|
}
|
|
|
|
MasterRecorder *gRecorder = nullptr; // lives as long as the app (the session never goes away)
|
|
NSURL *gLastTake = nil;
|
|
bool gArmed = false;
|
|
NSInteger gTail = 2;
|
|
|
|
} // namespace
|
|
|
|
@implementation SizzleSession (Record)
|
|
|
|
- (NSURL *)recordingsDirectory {
|
|
NSURL *docs = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].firstObject;
|
|
NSURL *dir = [docs URLByAppendingPathComponent:@"Recordings"];
|
|
[NSFileManager.defaultManager createDirectoryAtURL:dir withIntermediateDirectories:YES attributes:nil error:nil];
|
|
return dir;
|
|
}
|
|
|
|
- (void)rec_apply {
|
|
NSURL *dir = self.recordingsDirectory;
|
|
const bool armed = gArmed;
|
|
const int tail = (int)gTail;
|
|
[self edit:^(model::Project &, engine::Engine &e) {
|
|
if (!gRecorder) {
|
|
gRecorder = new MasterRecorder(e.sampleRate());
|
|
gRecorder->setPath([dir URLByAppendingPathComponent:@".take.wav"].path.UTF8String);
|
|
gRecorder->onStarted = [] {
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SizzleSessionDidChange object:nil];
|
|
});
|
|
};
|
|
gRecorder->onFinished = [dir](const std::string &path, int64_t start) {
|
|
NSURL *done = path.empty() ? nil : finishTake(dir, path, start);
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
if (done) gLastTake = done;
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:SizzleSessionDidChange object:nil];
|
|
});
|
|
};
|
|
e.setMasterSink(gRecorder);
|
|
}
|
|
e.setRecordingArm(armed, tail);
|
|
}];
|
|
}
|
|
|
|
- (BOOL)recordArmed { return gArmed; }
|
|
- (void)setRecordArmed:(BOOL)armed { gArmed = armed; [self rec_apply]; }
|
|
|
|
- (NSInteger)recordTailBars { return gTail; }
|
|
- (void)setRecordTailBars:(NSInteger)bars { gTail = std::clamp<NSInteger>(bars, 0, 4); [self rec_apply]; }
|
|
|
|
- (BOOL)masterRecording { return gRecorder && gRecorder->isActive(); }
|
|
- (nullable NSURL *)lastRecordingURL { return gLastTake; }
|
|
|
|
@end
|