0.37.0 (71): one engine, one version for Android and iOS
- 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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
64e21e0bcc
commit
2bc5cb1cbb
@@ -0,0 +1,112 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// AudioEngine.ChannelArp: per-(lane,track) arpeggiator. Notes are kept sorted
|
||||
// ascending; the linear step sequence is octave-major (all chord notes in octave 0,
|
||||
// then octave 1, ...), walked up / down / up-down / randomly by advance(). genStamp
|
||||
// identifies the line whose chord this holds (the engine's lineTriggerGen).
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace sizzle::engine {
|
||||
|
||||
class ChannelArp {
|
||||
public:
|
||||
int velocity = 100;
|
||||
double stepSamples = 0.0, samplesLeft = 0.0;
|
||||
bool resetOnBar = false;
|
||||
int genStamp = -1;
|
||||
|
||||
int noteCount() const { return noteCount_; }
|
||||
/** Active while it holds at least one note. */
|
||||
bool active() const { return noteCount_ > 0; }
|
||||
|
||||
/** Start a fresh chord on [note], resetting the phase to step 0. */
|
||||
void startChord(int note, int vel, int octs, const char *modeStr, double stepSamp, bool resetBar) {
|
||||
noteCount_ = 0; addNote(note); velocity = vel; octaves = clamp(octs, 1, 4);
|
||||
mode = modeOf(modeStr);
|
||||
stepSamples = stepSamp < 1.0 ? 1.0 : stepSamp; samplesLeft = stepSamples; step = 0; dir = 1;
|
||||
resetOnBar = resetBar; pendingReset = false;
|
||||
}
|
||||
|
||||
/** Replace the chord with [note] while keeping the running phase. */
|
||||
void resetChord(int note, int vel, int octs, const char *modeStr, double stepSamp, bool resetBar) {
|
||||
noteCount_ = 0; addNote(note); velocity = vel;
|
||||
refresh(octs, modeStr, stepSamp, resetBar);
|
||||
}
|
||||
|
||||
/** Add a note to the held chord (sorted ascending, de-duplicated). */
|
||||
void addNote(int note) {
|
||||
const int n = clamp(note, 0, 127);
|
||||
int i = 0;
|
||||
while (i < noteCount_ && notes[i] < n) i++;
|
||||
if (i < noteCount_ && notes[i] == n) return;
|
||||
if (noteCount_ >= MAX_CHORD) return;
|
||||
for (int j = noteCount_; j >= i + 1; --j) notes[j] = notes[j - 1];
|
||||
notes[i] = n; noteCount_++;
|
||||
}
|
||||
|
||||
/** Update params without resetting the running phase. */
|
||||
void refresh(int octs, const char *modeStr, double stepSamp, bool resetBar) {
|
||||
octaves = clamp(octs, 1, 4);
|
||||
mode = modeOf(modeStr);
|
||||
stepSamples = stepSamp < 1.0 ? 1.0 : stepSamp;
|
||||
resetOnBar = resetBar;
|
||||
}
|
||||
|
||||
void resetToBar() { step = 0; dir = 1; samplesLeft = 0.0; pendingReset = true; }
|
||||
bool consumePendingReset() { bool p = pendingReset; pendingReset = false; return p; }
|
||||
|
||||
void stop() { noteCount_ = 0; genStamp = -1; }
|
||||
|
||||
int currentNote() const {
|
||||
if (noteCount_ <= 0) return 0;
|
||||
const int idx = clamp(step, 0, total() - 1);
|
||||
const int oct = idx / noteCount_;
|
||||
return clamp(notes[idx % noteCount_] + 12 * oct, 0, 127);
|
||||
}
|
||||
|
||||
void advance() {
|
||||
const int t = total();
|
||||
switch (mode) {
|
||||
case 1: step = (step - 1 + t) % t; break;
|
||||
case 2:
|
||||
if (t > 1) {
|
||||
step += dir;
|
||||
if (step >= t - 1) { step = t - 1; dir = -1; }
|
||||
else if (step <= 0) { step = 0; dir = 1; }
|
||||
}
|
||||
break;
|
||||
case 3: step = t > 1 ? rnd(t) : 0; break;
|
||||
default: step = (step + 1) % t; break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr int MAX_CHORD = 8;
|
||||
static int clamp(int v, int lo, int hi) { return v < lo ? lo : (v > hi ? hi : v); }
|
||||
static int modeOf(const char *m) {
|
||||
if (std::strcmp(m, "Down") == 0) return 1;
|
||||
if (std::strcmp(m, "UpDown") == 0) return 2;
|
||||
if (std::strcmp(m, "Random") == 0) return 3;
|
||||
return 0;
|
||||
}
|
||||
int total() const { int t = noteCount_ * octaves; return t < 1 ? 1 : t; }
|
||||
int rnd(int bound) {
|
||||
uint32_t s = rng;
|
||||
s ^= s << 13; s ^= s >> 17; s ^= s << 5;
|
||||
rng = s;
|
||||
return (int)(s % (uint32_t)bound);
|
||||
}
|
||||
|
||||
int notes[MAX_CHORD] = {};
|
||||
int noteCount_ = 0;
|
||||
int octaves = 1, mode = 0;
|
||||
int step = 0, dir = 1;
|
||||
bool pendingReset = false;
|
||||
uint32_t rng = 0x2545F491u;
|
||||
};
|
||||
|
||||
} // namespace sizzle::engine
|
||||
Reference in New Issue
Block a user