iOS 0.6.0: milestone 5 (recording, MIDI, input bindings, themes, bundles, backups)
- Master recording (MasterSink ring + writer thread) and the sample recorder - CoreMIDI in/out: sound module, clock send/follow, virtual "Sizzle" ports; platform-free parser/module/clock in core (midi_test) - Hardware keyboard and gamepads via GameController; rebindable keyboard, gamepad and MIDI CC actions; per-parameter MIDI learn - Colour themes (.szt), project bundles (.szgz), backup & restore; ZIP in core with zlib (zip_test against jar and unzip) - Persistent app settings; audio pauses in the background unless sound module Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
435305e42a
commit
64e21e0bcc
@@ -47,6 +47,9 @@ struct NoteQueue {
|
||||
}
|
||||
};
|
||||
|
||||
/// The app paused the output on purpose (background, idle): don't restart it on a route change.
|
||||
bool gAudioSuspended = false;
|
||||
|
||||
constexpr int kChunk = 192; // Android's block size: keeps the MIDI LFO's rate (see PORTING.md)
|
||||
|
||||
NSError *sessionError(NSString *msg) {
|
||||
@@ -100,6 +103,7 @@ bool isSampleKey(const char *key) {
|
||||
std::unique_ptr<sampler::SampleStore> _store;
|
||||
std::unique_ptr<engine::Engine> _engine;
|
||||
NoteQueue _notes;
|
||||
NoteQueue _midiNotes; // pushed by the MIDI threads (serialised by the sound module's lock)
|
||||
std::vector<float> _scratch;
|
||||
AVAudioEngine *_audio;
|
||||
AVAudioSourceNode *_source;
|
||||
@@ -158,6 +162,26 @@ bool isSampleKey(const char *key) {
|
||||
if (getenv("SIZZLE_NO_AUDIO")) return; // the Mac snapshot tool: no sound
|
||||
NSError *err = nil;
|
||||
if (![_audio startAndReturnError:&err]) NSLog(@"Sizzle audio: %@", err);
|
||||
// A route or category change (the sample recorder switches to play-and-record,
|
||||
// headphones, an audio interface) stops the engine; an interruption (a call)
|
||||
// ends with it stopped. Start it again either way.
|
||||
AVAudioEngine *audio = _audio;
|
||||
void (^restart)(NSNotification *) = ^(NSNotification *) {
|
||||
if (audio.isRunning || gAudioSuspended) return;
|
||||
#if TARGET_OS_IPHONE
|
||||
[[AVAudioSession sharedInstance] setActive:YES error:nil];
|
||||
#endif
|
||||
NSError *e = nil;
|
||||
if (![audio startAndReturnError:&e]) NSLog(@"Sizzle audio restart: %@", e);
|
||||
};
|
||||
NSNotificationCenter *nc = NSNotificationCenter.defaultCenter;
|
||||
[nc addObserverForName:AVAudioEngineConfigurationChangeNotification object:_audio queue:NSOperationQueue.mainQueue usingBlock:restart];
|
||||
#if TARGET_OS_IPHONE
|
||||
[nc addObserverForName:AVAudioSessionInterruptionNotification object:nil queue:NSOperationQueue.mainQueue
|
||||
usingBlock:^(NSNotification *n) {
|
||||
if ([n.userInfo[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue] == AVAudioSessionInterruptionTypeEnded) restart(n);
|
||||
}];
|
||||
#endif
|
||||
}
|
||||
|
||||
/// The audio thread. Never blocks: if the song is being edited, this block is silent.
|
||||
@@ -180,6 +204,9 @@ bool isSampleKey(const char *key) {
|
||||
case 3: e->auditionSlotOff(n.b); break;
|
||||
}
|
||||
});
|
||||
_midiNotes.drain([e](const NoteEvent &n) {
|
||||
if (n.kind == 0) e->busNoteOn(n.a, n.b, n.c); else e->busNoteOff(n.a, n.b);
|
||||
});
|
||||
float *buf = _scratch.data();
|
||||
for (AVAudioFrameCount done = 0; done < frames;) {
|
||||
int n = (int)std::min<AVAudioFrameCount>(kChunk, frames - done);
|
||||
@@ -335,6 +362,25 @@ bool isSampleKey(const char *key) {
|
||||
- (void)stop { [self edit:^(model::Project &, engine::Engine &e) { e.stop(); }]; }
|
||||
- (void)panic { [self edit:^(model::Project &, engine::Engine &e) { e.panic(); }]; }
|
||||
- (BOOL)isPlaying { return _engine->isPlaying(); }
|
||||
|
||||
- (BOOL)audioSuspended { return !_audio.isRunning; }
|
||||
- (void)setAudioSuspended:(BOOL)suspended {
|
||||
if (getenv("SIZZLE_NO_AUDIO")) return;
|
||||
gAudioSuspended = suspended;
|
||||
if (suspended) { [_audio pause]; return; }
|
||||
if (_audio.isRunning) return;
|
||||
#if TARGET_OS_IPHONE
|
||||
[[AVAudioSession sharedInstance] setActive:YES error:nil];
|
||||
#endif
|
||||
NSError *e = nil;
|
||||
if (![_audio startAndReturnError:&e]) NSLog(@"Sizzle audio resume: %@", e);
|
||||
}
|
||||
|
||||
#pragma mark - MIDI threads (SizzleSession+Internal.h)
|
||||
- (void)midiNoteOn:(int)note velocity:(int)velocity channel:(int)channel { _midiNotes.push({0, channel, note, velocity}); }
|
||||
- (void)midiNoteOff:(int)note channel:(int)channel { _midiNotes.push({1, channel, note, 0}); }
|
||||
- (engine::Engine *)enginePointer { return _engine.get(); }
|
||||
- (const model::Project *)projectPointer { return _project.get(); }
|
||||
- (NSInteger)currentLine { return _engine->transport().currentLine; }
|
||||
- (NSInteger)currentBeat { return _engine->transport().currentBeat; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user