Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

(feat) Add root note to Grain

Egor Khindikaynend4286e84fe98
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 586e2603..8bb10cd4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,11 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
computer the first time a preset needs one, so they don't add to the download. The
Basics presets still keep whatever sample you dropped in. Previews in the browser play
each preset with its own source.
+- **Nota Grain lets you set the root note of your own sample.** The Pitch tab has a ROOT
+ control: the key that plays the sample at its recorded pitch. Step it with − / + or the
+ mouse wheel. When you drop a file whose name names a note ("Pad_F#3.wav"), Grain takes
+ the root from it; otherwise it's C4. Double-click the root to go back to the one in the
+ file name. The root is saved with the project.
- Import MIDI files. `.mid` files now show up in the browser's Files tab, and you can drag
them from there or straight from Finder / Explorer. Drop one on the arrangement and it
becomes a MIDI clip at that spot. A file with several parts spreads out: the first part
diff --git a/src/managed/Nota.App/DeviceCards/Instruments/GrainInstrumentCard.cs b/src/managed/Nota.App/DeviceCards/Instruments/GrainInstrumentCard.cs
index ada265ae..0b1b7abb 100644
--- a/src/managed/Nota.App/DeviceCards/Instruments/GrainInstrumentCard.cs
+++ b/src/managed/Nota.App/DeviceCards/Instruments/GrainInstrumentCard.cs
@@ -10,7 +10,8 @@
// controls beneath the graph:
// Grain — the window shape (Hann · Gauss · Tukey · Tri) as drawn chips,
// then size, density and spread.
-// Pitch — coarse and fine.
+// Pitch — the root (the key that plays the sample as recorded; a drop
+// takes it from a note in the file name), coarse and fine.
// Variation — per-grain position, pitch and pan jitter.
// Filter — LP / HP / BP, cutoff and resonance, after the cloud.
// Amp — the envelope of the whole cloud.
@@ -109,11 +110,15 @@ internal sealed class GrainInstrumentCard : IInstrumentCard
var wave = new GrainWaveViz { VerticalAlignment = VerticalAlignment.Stretch };
long sampleId = -1;
double sampleSec = 0, sampleKHz = 0;
+ int rootNote = 60;
+ string sampleName = "";
void LoadPeaks()
{
engine.TryGetGrainInfo(track, out var gi);
+ rootNote = gi.RootNote;
if (gi.SampleId == sampleId) return;
sampleId = gi.SampleId;
+ sampleName = gi.SampleId != 0 ? engine.SampleName(gi.SampleId) : "";
if (gi.SampleId != 0 && engine.TryGetSampleInfo(gi.SampleId, out var si) && si.Channels > 0 && si.Frames > 0)
{
var raw = engine.ReadSample(gi.SampleId);
@@ -275,6 +280,48 @@ internal sealed class GrainInstrumentCard : IInstrumentCard
return sp;
}
+ // The root: the key that plays the sample at its own pitch — a stepper, since it
+ // belongs to the sample (saved with it) rather than being an automatable param.
+ Control RootCell()
+ {
+ void SetRoot(int n) { rootNote = Math.Clamp(n, 0, 127); engine.SetTrackGrainRoot(track, rootNote); Refresh(); }
+ var text = Mono(SamplerModel.NoteName(rootNote), TextPrimary, 9);
+ text.HorizontalAlignment = HorizontalAlignment.Center;
+ readouts.Add(() => text.Text = SamplerModel.NoteName(rootNote));
+ Border Step(GlyphKind g, int d, string tip)
+ {
+ var b = new Border
+ {
+ Width = 16, Height = 17, CornerRadius = NotaRadius.Badge, BorderThickness = new Thickness(1),
+ BorderBrush = BorderDef, Background = NotaPalette.SurfaceRaised, Cursor = new Cursor(StandardCursorType.Hand),
+ Child = new Glyph(g, 7) { Foreground = NotaPalette.TextStrong, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center },
+ };
+ ToolTip.SetTip(b, tip);
+ b.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(b).Properties.IsLeftButtonPressed) return;
+ SetRoot(rootNote + d); e.Handled = true;
+ };
+ return b;
+ }
+ var box = new Border
+ {
+ Height = 17, MinWidth = 40, CornerRadius = NotaRadius.Badge, BorderThickness = new Thickness(1), BorderBrush = BorderDef,
+ Background = NotaPalette.BgSunken, Child = text,
+ };
+ box.PointerWheelChanged += (_, e) => { SetRoot(rootNote + (e.Delta.Y > 0 ? 1 : -1)); e.Handled = true; };
+ // Double-click: the note the file name names, else C4.
+ box.DoubleTapped += (_, e) => { SetRoot(SamplerModel.DetectRoot(sampleName) is var d and >= 0 ? d : 60); e.Handled = true; };
+ ToolTip.SetTip(box, "The root — the key that plays the sample as recorded. Scroll to step it · double-click takes it from the file name (C4 if none)");
+ var stepper = new StackPanel
+ {
+ Orientation = Orientation.Horizontal, Spacing = 4,
+ Children = { Step(GlyphKind.Minus, -1, "Root a semitone down"), box, Step(GlyphKind.Plus, +1, "Root a semitone up") },
+ };
+ var cap = Cap("ROOT"); cap.HorizontalAlignment = HorizontalAlignment.Center;
+ return new StackPanel { Spacing = 4, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 8, 0), Children = { cap, stepper } };
+ }
+
// ---- the tabs ---------------------------------------------------------
var filterChips = Chips("filtype", FilterNames, "Filter Type");
filterChips.Margin = new Thickness(0, 0, 8, 0);
@@ -286,7 +333,8 @@ internal sealed class GrainInstrumentCard : IInstrumentCard
PKnob("grainsize", "SIZE", "Grain Size", Size),
PKnob("density", "DENSITY", "Density", Density),
PKnob("spread", "SPREAD", "Spread", Pct, arc: Teal)),
- Row(PKnob("coarse", "COARSE", "Coarse", Coarse),
+ Row(RootCell(),
+ PKnob("coarse", "COARSE", "Coarse", Coarse),
PKnob("fine", "FINE", "Fine", Fine)),
Row(PKnob("posrand", "POSITION", "Pos Rand", Pct, arc: Teal),
PKnob("pitchrand", "PITCH", "Pitch Rand", PitchJitter, arc: Teal),
@@ -430,7 +478,7 @@ internal sealed class GrainInstrumentCard : IInstrumentCard
string Hint() => tab switch
{
0 => $"{ModeWord()} · {ShapeWords[Sel("grainshape", 4)]} · {Size(G("grainsize"))} · {Density(G("density"))}",
- 1 => $"{ModeWord()} · {Coarse(G("coarse"))} · {Fine(G("fine"))}",
+ 1 => $"{ModeWord()} · root {SamplerModel.NoteName(rootNote)} · {Coarse(G("coarse"))} · {Fine(G("fine"))}",
2 => $"{ModeWord()} · position · pitch · pan",
3 => $"{ModeWord()} · {FilterNames[Sel("filtype", 3)]} · {Hz(G("filfreq"))}",
_ => $"{ModeWord()} · a · d · s · r",
@@ -439,8 +487,8 @@ internal sealed class GrainInstrumentCard : IInstrumentCard
{
0 => $"Window {ShapeWords[Sel("grainshape", 4)]} · size {Size(G("grainsize"))} · density {Density(G("density"))} · spread {Pct(G("spread"))} · {Read()}{Mix()}",
1 => Math.Abs(G("coarse") - 0.5f) < 0.001f && Math.Abs(G("fine") - 0.5f) < 0.0026f
- ? "Coarse 0 · fine 0 — the grains play at the note's pitch"
- : $"Coarse {Coarse(G("coarse"))} · fine {Fine(G("fine"))} — every grain transposed by it",
+ ? $"Root {SamplerModel.NoteName(rootNote)} plays the sample as recorded · coarse 0 · fine 0"
+ : $"Root {SamplerModel.NoteName(rootNote)} · coarse {Coarse(G("coarse"))} · fine {Fine(G("fine"))} — every grain transposed by it",
2 => $"Variation: position {Pct(G("posrand"))} · pitch {PitchJitter(G("pitchrand"))} · pan {Pct(G("panrand"))} — per grain",
3 => $"Filter {FilterNames[Sel("filtype", 3)]} · {Hz(G("filfreq"))} · reso {Pct(G("filreso"))} — after the grain cloud",
_ => $"Amp {Attack(G("attack"))} · {Decay(G("decay"))} · {Pct(G("sustain"))} · {Release(G("release"))} — the envelope shapes the cloud, not the grain",
diff --git a/src/managed/Nota.App/MainWindow.Dnd.cs b/src/managed/Nota.App/MainWindow.Dnd.cs
index 0c895c08..185a3fb0 100644
--- a/src/managed/Nota.App/MainWindow.Dnd.cs
+++ b/src/managed/Nota.App/MainWindow.Dnd.cs
@@ -222,9 +222,13 @@ public partial class MainWindow
else { ShowDevices(t); _vm.StatusText = $"Loaded {item.Name}"; }
break;
case BrowserItemKind.Sample when kind == 10: // sample → load into Nota Grain
- if (!Engine.SetTrackGrainSample(t, item.Path, 60)) _vm.StatusText = $"Couldn't load {item.Name}.";
- else { ShowDevices(t); _vm.StatusText = $"Loaded {item.Name}"; }
+ {
+ // The root from a note in the file name ("Pad_F#3.wav"), else C4.
+ int root = SamplerModel.DetectRoot(item.Path) is var d and >= 0 ? d : 60;
+ if (!Engine.SetTrackGrainSample(t, item.Path, root)) _vm.StatusText = $"Couldn't load {item.Name}.";
+ else { ShowDevices(t); _vm.StatusText = $"Loaded {item.Name} · root {SamplerModel.NoteName(root)}"; }
break;
+ }
case BrowserItemKind.Sample:
_vm.StatusText = "Drop samples onto the arrangement.";
break;
diff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.cs
index 28a4eaf3..bdc1d9fa 100644
--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs
+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs
@@ -300,6 +300,8 @@ public interface IAudioEngine : IDisposable
void InstrumentAction(int trackId, int id, int iarg, float farg);
/// <summary>Loads a sample file into a Nota Grain track (kind 10). True on success.</summary>
bool SetTrackGrainSample(int trackId, string path, int rootNote = 60);
+ /// <summary>Sets a Nota Grain's root note — the key that plays the sample at its own pitch.</summary>
+ bool SetTrackGrainRoot(int trackId, int rootNote);
/// <summary>Grain sample info (sample id / root). True if the track is a Nota Grain.</summary>
bool TryGetGrainInfo(int trackId, out NotaSamplerInfo info);
/// <summary>Nota Rhythm Phase 2 — load a one-shot into a drum voice (switches it to Sample).</summary>
diff --git a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
index 287565ea..3ed20c39 100644
--- a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
@@ -350,6 +350,9 @@ internal static partial class NativeMethods
[LibraryImport(Lib, EntryPoint = "nota_track_set_grain_sample", StringMarshalling = StringMarshalling.Utf8)]
internal static partial int SetTrackGrainSample(IntPtr engine, int trackId, string path, int rootNote);
+ [LibraryImport(Lib, EntryPoint = "nota_track_set_grain_root")]
+ internal static partial int SetTrackGrainRoot(IntPtr engine, int trackId, int rootNote);
+
[LibraryImport(Lib, EntryPoint = "nota_track_grain_info")]
internal static partial int TrackGrainInfo(IntPtr engine, int trackId, out NotaSamplerInfo info);
diff --git a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
index aa6e566e..0f086c61 100644
--- a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
@@ -750,6 +750,9 @@ public sealed partial class NotaEngine
public bool SetTrackGrainSample(int trackId, string path, int rootNote = 60)
{ ThrowIfDisposed(); return NativeMethods.SetTrackGrainSample(_handle, trackId, path, rootNote) != 0; }
+ public bool SetTrackGrainRoot(int trackId, int rootNote)
+ { ThrowIfDisposed(); return NativeMethods.SetTrackGrainRoot(_handle, trackId, rootNote) != 0; }
+
public bool TryGetGrainInfo(int trackId, out NotaSamplerInfo info)
{ ThrowIfDisposed(); return NativeMethods.TrackGrainInfo(_handle, trackId, out info) != 0; }
diff --git a/src/managed/Nota.Mcp/Tools/SampleTools.cs b/src/managed/Nota.Mcp/Tools/SampleTools.cs
index 48a330b0..69be5980 100644
--- a/src/managed/Nota.Mcp/Tools/SampleTools.cs
+++ b/src/managed/Nota.Mcp/Tools/SampleTools.cs
@@ -219,17 +219,24 @@ public sealed class SampleTools(IAudioEngine engine, IEngineDispatch dispatch, I
private static double Db(float lin) => lin <= 1e-5f ? -100 : 20 * Math.Log10(lin);
[McpServerTool(Name = "add_grain_track"), Description(
- "Add a Grain (granular) instrument track and load an audio file to granulate. Returns the track id.")]
- public Task<int> AddGrainTrack(string path, int rootNote = 60) => Mutate(() =>
+ "Add a Grain (granular) instrument track and load an audio file to granulate. Returns the track id. detectRoot = take the "
+ + "root from a note in the file name, falling back to rootNote.")]
+ public Task<int> AddGrainTrack(string path, int rootNote = 60, bool detectRoot = false) => Mutate(() =>
{
int id = E.AddGrainSynthTrack();
- if (id > 0) E.SetTrackGrainSample(id, path, rootNote);
+ if (id > 0) E.SetTrackGrainSample(id, path, RootFor(path, rootNote, detectRoot));
return id;
});
- [McpServerTool(Name = "load_grain_sample"), Description("Load an audio file into an existing Grain granular track (kind 10).")]
- public Task<bool> LoadGrainSample(int trackId, string path, int rootNote = 60)
- => Mutate(() => E.SetTrackGrainSample(trackId, path, rootNote));
+ [McpServerTool(Name = "load_grain_sample"), Description(
+ "Load an audio file into an existing Grain granular track (kind 10). detectRoot = take the root from a note in the file "
+ + "name, falling back to rootNote.")]
+ public Task<bool> LoadGrainSample(int trackId, string path, int rootNote = 60, bool detectRoot = false)
+ => Mutate(() => E.SetTrackGrainSample(trackId, path, RootFor(path, rootNote, detectRoot)));
+
+ [McpServerTool(Name = "set_grain_root"), Description(
+ "Set a Grain track's root note (the MIDI note that plays the sample at its original pitch, C4 = 60).")]
+ public Task<bool> SetGrainRoot(int trackId, int rootNote) => Mutate(() => E.SetTrackGrainRoot(trackId, rootNote));
[McpServerTool(Name = "get_grain_info"), Description("Read a Grain track's loaded sample: root note, channels, frame count, sample rate.")]
public Task<SamplerInfo> GetGrainInfo(int trackId) => Read(() =>
diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.h
index 8a7f034b..88ce8916 100644
--- a/src/native/nota.engine/include/nota/nota_engine.h
+++ b/src/native/nota.engine/include/nota/nota_engine.h
@@ -572,6 +572,8 @@ NOTA_API int32_t nota_engine_add_sampler_instrument_track(NotaEngine* engine);
NOTA_API int32_t nota_track_set_sampler_sample(NotaEngine* engine, int32_t track_id, const char* path_utf8, int32_t root_note);
/* Loads a sample file into an existing Nota Grain track (kind 10, keeps params). 1 = ok. */
NOTA_API int32_t nota_track_set_grain_sample(NotaEngine* engine, int32_t track_id, const char* path_utf8, int32_t root_note);
+/* Sets the Grain's root note — the key that plays the sample at its own pitch (lock-free). 1 = ok. */
+NOTA_API int32_t nota_track_set_grain_root(NotaEngine* engine, int32_t track_id, int32_t root_note);
/* Sets the Sampler's root note (lock-free). 1 = ok. */
NOTA_API int32_t nota_track_set_sampler_root(NotaEngine* engine, int32_t track_id, int32_t root_note);
/* Live playback position of the Sampler (0..1 of the sample, -1 = silent) for the UI cursor. */
diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.h
index d42b0013..4d1b7396 100644
--- a/src/native/nota.engine/src/Engine.h
+++ b/src/native/nota.engine/src/Engine.h
@@ -585,6 +585,7 @@ public:
bool rhythmSetMacroMappingCurve(int32_t trackId, int32_t index, int32_t curve);
void rhythmClearMacros(int32_t trackId);
bool setTrackGrainSample(int32_t trackId, const std::string& path, int32_t rootNote);
+ bool setTrackGrainRoot(int32_t trackId, int32_t rootNote);
int32_t addSamplerTrack(const std::string& path, int32_t rootNote, bool loop);
int32_t addSamplerInstrumentTrack(); // empty Sampler (sample loaded later)
bool setTrackSamplerSample(int32_t trackId, const std::string& path, int32_t rootNote);
diff --git a/src/native/nota.engine/src/Engine_Devices.cpp b/src/native/nota.engine/src/Engine_Devices.cpp
index cd5c02f4..01c8a6d9 100644
--- a/src/native/nota.engine/src/Engine_Devices.cpp
+++ b/src/native/nota.engine/src/Engine_Devices.cpp
@@ -282,6 +282,14 @@ bool Engine::setTrackGrainSample(int32_t trackId, const std::string& path, int32
return true;
}
+bool Engine::setTrackGrainRoot(int32_t trackId, int32_t rootNote) {
+ auto t = findTrackAuthoring(trackId);
+ auto* gr = t && t->instrument ? dynamic_cast<GrainSynth*>(t->instrument.get()) : nullptr;
+ if (!gr) return false;
+ gr->setRoot(rootNote); // lock-free atomic; the synth is shared across snapshots
+ return true;
+}
+
int32_t Engine::addSamplerTrack(const std::string& path, int32_t rootNote, bool loop) {
auto sample = decodeAudioFile(path);
if (!sample || sample->empty()) return 0;
diff --git a/src/native/nota.engine/src/GrainSynth.h b/src/native/nota.engine/src/GrainSynth.h
index d8ca3668..6c8e2ce4 100644
--- a/src/native/nota.engine/src/GrainSynth.h
+++ b/src/native/nota.engine/src/GrainSynth.h
@@ -70,7 +70,8 @@ public:
// Sample plumbing — mirrors Sampler so the engine's sample-load / bundling reuse it.
std::shared_ptr<SampleBuffer> sample() const { return sample_; }
- int32_t rootNote() const { return rootNote_; }
+ int32_t rootNote() const { return rootNote_.load(std::memory_order_relaxed); }
+ void setRoot(int32_t r) { rootNote_.store(std::clamp(r, 0, 127), std::memory_order_relaxed); }
bool loopEnabled() const { return false; }
// Live read positions of the active voices (0..1 through the sample), for the UI's
@@ -94,7 +95,7 @@ public:
}
void setSample(std::shared_ptr<SampleBuffer> s, int32_t rootNote, bool /*loop*/) {
- if (s && !s->empty()) { sample_ = std::move(s); rootNote_ = rootNote; }
+ if (s && !s->empty()) { sample_ = std::move(s); setRoot(rootNote); }
}
// ---- parameters ----
@@ -137,7 +138,7 @@ public:
std::shared_ptr<Instrument> clone() const override {
auto s = std::make_shared<GrainSynth>();
for (int i = 0; i < kNumParams; ++i) s->pn_[i].store(pn_[i].load(std::memory_order_relaxed), std::memory_order_relaxed);
- s->sample_ = sample_; s->rootNote_ = rootNote_; s->setSampleRate(sampleRate_);
+ s->sample_ = sample_; s->setRoot(rootNote()); s->setSampleRate(sampleRate_);
return s;
}
@@ -179,6 +180,7 @@ public:
const double spread = get(Spread);
const double posRandFr = (double)get(PosRand) * 0.25 * slen;
const double pitchRand = (double)get(PitchRand) * 12.0;
+ const int root = rootNote();
const double panRand = get(PanRand);
const int ftype = std::clamp((int)std::lround(get(FilterType) * 2.0f), 0, 2);
const double fbase = expMap(get(FilterFreq), 60.0, 18000.0);
@@ -202,7 +204,7 @@ public:
if (!v.active) continue;
v.base = basePos01(v.pitch, mode) * slen;
if (mode != 0) v.scanOff = 0.0;
- const double semis = (mode == 2 ? 0.0 : (v.pitch - rootNote_)) + coarse + fine;
+ const double semis = (mode == 2 ? 0.0 : (v.pitch - root)) + coarse + fine;
v.dryRate = std::pow(2.0, semis / 12.0) * srcRatio;
}
@@ -240,7 +242,7 @@ public:
if (g) {
double pos = v.readPos + (sprayFr + posRandFr) * (rnd() * 2.0 - 1.0);
pos = std::clamp(pos, 0.0, (double)std::max<int64_t>(0, slen - 2));
- const double semis = (mode == 2 ? 0.0 : (v.pitch - rootNote_)) + coarse + fine + pitchRand * (rnd() * 2.0 - 1.0);
+ const double semis = (mode == 2 ? 0.0 : (v.pitch - root)) + coarse + fine + pitchRand * (rnd() * 2.0 - 1.0);
g->pos = pos; g->age = 0.0; g->len = grainLen;
g->rate = std::pow(2.0, semis / 12.0) * srcRatio;
double pan = 0.5 + (spread * 0.5 + panRand * 0.5) * (rnd() * 2.0 - 1.0);
@@ -385,7 +387,7 @@ private:
}
double sampleRate_ = 44100.0;
- int32_t rootNote_ = 60;
+ std::atomic<int32_t> rootNote_{60};
std::shared_ptr<SampleBuffer> sample_;
uint32_t rng_ = 0x1234567u;
std::atomic<float> pn_[kNumParams];
diff --git a/src/native/nota.engine/src/nota_engine_track.cpp b/src/native/nota.engine/src/nota_engine_track.cpp
index 6f0bac77..2dfcb90f 100644
--- a/src/native/nota.engine/src/nota_engine_track.cpp
+++ b/src/native/nota.engine/src/nota_engine_track.cpp
@@ -246,6 +246,9 @@ int32_t nota_track_set_grain_sample(NotaEngine* e, int32_t track_id, const char*
if (!e || !path) return 0;
return ENG(e)->setTrackGrainSample(track_id, std::string(path), root) ? 1 : 0;
}
+int32_t nota_track_set_grain_root(NotaEngine* e, int32_t track_id, int32_t root) {
+ return (e && ENG(e)->setTrackGrainRoot(track_id, root)) ? 1 : 0;
+}
int32_t nota_track_grain_info(const NotaEngine* e, int32_t track_id, NotaSamplerInfo* out) {
return (e && CENG(e)->grainInfo(track_id, out)) ? 1 : 0;
}
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index 636b915e..815fd3bc 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -2795,6 +2795,8 @@ Console.WriteLine("-- Nota Grain --");
{ int n = 16000; var sp = new float[n]; for (int i = 0; i < n; i++) sp[i] = (float)(Math.Sin(2 * Math.PI * 330 * i / 32000.0) * 0.5); using var w = new Nota.Infrastructure.WavWriter(gpath, 32000, 1, WavBitDepth.Float32); w.WriteFrames(sp, n); }
Check(ge.SetTrackGrainSample(t, gpath, 60), "loads a sample into Nota Grain");
Check(ge.TryGetGrainInfo(t, out var giS) && giS.SampleId != 0, "grain reports its loaded sample id");
+ Check(ge.SetTrackGrainRoot(t, 57) && ge.TryGetGrainInfo(t, out var giRoot) && giRoot.RootNote == 57 && giRoot.SampleId == giS.SampleId,
+ "set grain root keeps the sample and reports the new root");
ge.PluginParamSet(t, -1, posI, 0.4f);
string gdir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "nota-grain-proj-" + System.Guid.NewGuid().ToString("N"));
@@ -2810,6 +2812,7 @@ Console.WriteLine("-- Nota Grain --");
ProjectService.Apply(gloaded, gdst, gdir);
int rt = -1; for (int i = 0; i < gdst.TrackCount; i++) if (gdst.TryGetTrackInfo(i, out var tinf) && gdst.TrackInstrumentKind(tinf.Id) == 10) { rt = tinf.Id; break; }
Check(rt > 0 && gdst.TryGetGrainInfo(rt, out var giR) && giR.SampleId != 0, "reloaded Grain still has its sample");
+ Check(rt > 0 && gdst.TryGetGrainInfo(rt, out var giRR) && giRR.RootNote == 57, "reloaded Grain keeps its root note");
Check(rt > 0 && Math.Abs(gdst.PluginParamGet(rt, -1, posI) - 0.4f) < 1e-3, "reloaded Grain restores its params");
}
finally { try { System.IO.Directory.Delete(gdir, true); } catch { } try { System.IO.File.Delete(gpath); } catch { } }