| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- // Round 165p: issue #12 (BURNER1PA, Windows 10, 0.1.18)
- // Bug: Metronome given 'C' did nothing — the focused Playlist / Piano Roll took 'C' for its Knife first. Now the
- // editors' tools and letters are key map actions, and a key the user chose wins over the panels' built-in keys.
- TEST (issue12_user_key_wins_over_a_panel_default)
- {
- using namespace lynx::keys;
- KeyMap map;
- CHECK (map.conflicts().empty());
- CHECK (map.find ({ 'C' }, Context::playlist, false) == "playlist.tool.knife");
- CHECK (map.find ({ 'C' }, Context::pianoRoll, false) == "pianoRoll.tool.knife");
- CHECK (map.find ({ 'S' }, Context::playlist, false) == "playlist.tool.slip");
- CHECK (map.find ({ 'S' }, Context::pianoRoll, false) == "pianoRoll.slide");
- CHECK (map.find ({ 'N' }, Context::pianoRoll, false) == "pianoRoll.tool.drumPaint");
- CHECK (map.find ({ 'N' }, Context::playlist, false).empty()); // (no drum brush in the Playlist)
- CHECK (map.find ({ 'C' }, Context::playlist, true).empty()); // typing piano on: the letter plays a note
- CHECK (map.findUserBound ({ 'C' }, Context::playlist, false).empty()); // nothing chosen by the user yet
- map.setChords ("transport.metronome", { { 'C' } });
- for (auto focus : { Context::global, Context::channelRack, Context::pianoRoll, Context::playlist, Context::mixer, Context::browser })
- CHECK (map.findUserBound ({ 'C' }, focus, false) == "transport.metronome");
- CHECK (map.findUserBound ({ 'C' }, Context::playlist, true).empty()); // the typing piano still owns the letter
- CHECK (map.findUserBound ({ 'M', ctrl }, Context::global, false).empty()); // the old default key is gone
- const auto shadowed = map.shadowedBy ({ 'C' }, "transport.metronome");
- CHECK (shadowed.size() == 2);
- // a tool moved to another key works there, and its old letter is free
- map.setChords ("playlist.tool.knife", { { 'X' } });
- CHECK (map.findUserBound ({ 'X' }, Context::playlist, false) == "playlist.tool.knife");
- CHECK (map.findUserBound ({ 'X' }, Context::pianoRoll, false).empty());
- // both the user's: the focused panel's wins in the panel
- map.setChords ("pianoRoll.tool.listen", { { 'C' } });
- CHECK (map.findUserBound ({ 'C' }, Context::pianoRoll, false) == "pianoRoll.tool.listen");
- CHECK (map.findUserBound ({ 'C' }, Context::playlist, false) == "transport.metronome");
- }
- // Every action of the key map answers a key the user gives it, in every place it works (no panel swallows it).
- TEST (issue12_every_action_takes_a_user_key)
- {
- using namespace lynx::keys;
- const Chord picks[] = { { 'C' }, { 'Q', ctrl | shift }, { f3, alt }, { 'K', ctrl } };
- for (const auto& a : actions())
- for (const auto& c : picks)
- {
- KeyMap map;
- map.setChords (a.id, { c });
- const auto inDefaults = std::find (a.defaults.begin(), a.defaults.end(), c) != a.defaults.end();
- if (inDefaults)
- continue;
- const auto focus = a.context == Context::global ? Context::playlist : a.context;
- CHECK (map.findUserBound (c, focus, false) == a.id);
- CHECK (map.find (c, focus, false) == a.id || map.findUserBound (c, focus, false) == a.id);
- }
- }
- // Round 165q's find: on Windows JUCE's F-keys / numpad are VK | 0x10000, and the editors' towupper() turned F4 into
- // 'S' (the Slip tool) and F1 into 'P', so F4 (next empty pattern) did nothing with the Playlist focused.
- TEST (issue12_function_keys_are_not_letters)
- {
- using lynx::keys::letterOfKeyCode;
- for (int vk = 0x70; vk <= 0x7B; ++vk) // VK_F1…VK_F12, as JUCE's Windows key codes
- CHECK (letterOfKeyCode (vk | 0x10000) == 0);
- for (int vk = 0x60; vk <= 0x6F; ++vk) // the numpad
- CHECK (letterOfKeyCode (vk | 0x10000) == 0);
- for (int vk : { 0x25, 0x26, 0x27, 0x28, 0x21, 0x22, 0x24, 0x23, 0x2D, 0x2E }) // arrows, page, home, end, ins, del
- CHECK (letterOfKeyCode (vk | 0x10000) == 0);
- CHECK (letterOfKeyCode ('c') == 'C' && letterOfKeyCode ('S') == 'S' && letterOfKeyCode ('1') == '1');
- CHECK (letterOfKeyCode (' ') == 0 && letterOfKeyCode (0x7f) == 0);
- }
- // Bug: automation recorded in Song mode "cut itself": at the song's end the playhead went back to the start, the
- // points wrapped onto the start of the take's clip, and a pause in the gesture began a new clip. Now (song mode,
- // no loop region) the song plays on, the points keep their place, and the take's clip grows with the playhead.
- TEST (issue12_song_mode_automation_take_grows_past_the_song_end)
- {
- auto song = lynx::Song::makeDefault();
- song.mode = lynx::PlayMode::song;
- song.playlist.clear();
- song.automations.clear();
- lynx::Clip pc; // one bar of pattern: the song is one bar long
- pc.kind = lynx::ClipKind::pattern;
- pc.length = 4 * lynx::ppq;
- song.playlist.push_back (pc);
- const double bar = 4.0 * lynx::ppq;
- CHECK (lynx::songTickForRecorded (song, 1.5 * bar) == (std::int64_t) (0.5 * bar)); // (looping playback: wraps)
- CHECK (lynx::songTickForRecorded (song, 1.5 * bar, true) == (std::int64_t) (1.5 * bar));
- lynx::AutomationWrite w;
- w.target = { lynx::AutomationTargetKind::mixerVolume, 1 };
- w.name = "Insert 1 - Volume";
- lynx::commitAutomationPoints (song, w, { { 100, 0.2f }, { 400, 0.4f } }, 0, true);
- CHECK (w.createdByTake && w.automation == 0);
- auto clipOf = [&] () -> const lynx::Clip& {
- for (const auto& c : song.playlist)
- if (c.kind == lynx::ClipKind::automation)
- return c;
- return song.playlist.front();
- };
- CHECK (clipOf().start == 0 && clipOf().length == (std::int64_t) bar);
- // the playhead goes on (no move): the clip follows it, holding the value
- lynx::growTakeClip (song, w, (std::int64_t) (1.25 * bar), false);
- CHECK (clipOf().length == (std::int64_t) (1.25 * bar));
- // the gesture starts again in bar 3 (past the old song end): same clip, points where they were played
- w.lastLocal = -1; // (the engine: the first gesture ended)
- lynx::commitAutomationPoints (song, w, { { 2.5 * bar, 0.9f }, { 2.6 * bar, 1.0f } }, 0, true);
- int automationClips = 0;
- for (const auto& c : song.playlist)
- automationClips += c.kind == lynx::ClipKind::automation ? 1 : 0;
- CHECK (automationClips == 1 && song.automations.size() == 1);
- CHECK (clipOf().end() >= (std::int64_t) (2.6 * bar));
- const auto& a = song.automations[0];
- CHECK (std::abs (a.valueAt (150.0) - 0.25f) < 0.05f); // the start is not overwritten
- CHECK (std::abs (a.valueAt (1.2 * bar) - 0.4f) < 1e-6f); // held between the gestures
- CHECK (std::abs (a.valueAt (2.6 * bar) - 1.0f) < 1e-6f);
- // recording stops at 2.7 bars: the clip ends at the end of that bar
- lynx::growTakeClip (song, w, (std::int64_t) (2.7 * bar), true);
- CHECK (clipOf().end() == 3 * (std::int64_t) bar);
- }
- // Bug: a controller's pitch wheel played but was not recorded. Recording writes it as the channel's pitch bend
- // (MIDI pitch bend target, as for a hosted plugin); a LYNX instrument now plays that lane / clip as the wheel.
- TEST (issue12_recorded_pitch_bend_plays_on_a_lynx_instrument)
- {
- auto render = [] (bool withBend) {
- auto song = lynx::Song::makeDefault();
- song.mode = lynx::PlayMode::pattern;
- song.playlist.clear();
- auto& p = song.patterns[(std::size_t) song.currentPattern];
- p.notes.clear();
- lynx::Note n;
- n.channel = 4; // "Synth"
- n.key = 60;
- n.start = 0;
- n.length = 4 * lynx::ppq;
- p.notes.push_back (n);
- p.events.clear();
- if (withBend)
- {
- lynx::PatternEvents lane;
- lane.target = { lynx::AutomationTargetKind::channelParam, 4, 0, lynx::midictl::pitchBendBase };
- lane.events.push_back ({ 0, 1.0f }); // full bend up (+2 semitones, the channel's pitch range)
- p.events.push_back (lane);
- }
- auto state = lynx::RackState::build (song, nullptr, 48000.0);
- auto bound = false;
- for (const auto& b : state->pluginParams)
- bound = bound || (b.channel == 4 && b.param == lynx::midictl::pitchBendBase);
- lynx::RackRenderer renderer;
- renderer.prepare (48000.0, 512);
- std::vector<float> l (512), r (512), all;
- for (int block = 0; block < 16; ++block)
- {
- renderer.process (state.get(), true, block * 512.0 * lynx::ticksPerSample (song.bpm, 48000.0), 512, l.data(), r.data());
- all.insert (all.end(), l.begin(), l.end());
- }
- return std::make_pair (bound, all);
- };
- const auto plain = render (false), bent = render (true);
- CHECK (! plain.first && bent.first);
- // zero crossings over the same span: the bent note is higher (+2 semitones ≈ ×1.12)
- auto crossings = [] (const std::vector<float>& x) {
- int c = 0;
- for (std::size_t i = 4096; i + 1 < x.size(); ++i)
- c += (x[i] < 0.0f) != (x[i + 1] < 0.0f) ? 1 : 0;
- return c;
- };
- const auto a = crossings (plain.second), b = crossings (bent.second);
- // (C5 = 261.6 Hz: ~45 crossings in the 4096 samples measured; +2 semitones = x1.122)
- const auto ok = a > 30 && b * 100 > a * 105 && b * 100 < a * 120;
- if (! ok)
- std::printf (" pitch bend: %d crossings plain, %d bent\n", a, b);
- CHECK (ok);
- }
- // Issue #12: the Sampler's ADSR, cutoff, resonance, start and end are automation targets; the 0..1 values follow the
- // knobs' curves, and an automation clip / pattern event lane on them binds to the channel's instrument.
- TEST (issue12_sampler_knobs_are_automation_targets)
- {
- using namespace lynx;
- for (int k = 0; k < samplerparam::count; ++k)
- for (float v : { 0.0f, 0.25f, 0.5f, 0.9f, 1.0f })
- CHECK (std::abs (samplerparam::toValue (k, samplerparam::toNatural (k, v)) - v) < 1.0e-4f);
- // the knobs' mid points: attack 0.2 s, cutoff 1 kHz at half travel
- CHECK (std::abs (samplerparam::toNatural (samplerparam::attack, 0.5f) - 0.2f) < 1.0e-4f);
- CHECK (std::abs (samplerparam::toNatural (samplerparam::cutoff, 0.5f) - 1000.0f) < 0.05f);
- auto song = Song::makeDefault();
- song.channels[0].instrument = InstrumentKind::sampler;
- song.channels[0].sampler.flChannel = { 1, 2, 3 };
- const AutomationTarget cutoff { AutomationTargetKind::channelParam, 0, 0, samplerparam::cutoff };
- CHECK (song.setTargetValue (cutoff, 0.5f));
- CHECK (std::abs (song.channels[0].sampler.cutoff - 1000.0f) < 0.05f);
- CHECK (song.channels[0].sampler.flChannel.empty()); // like the knob turned by hand
- CHECK (std::abs (song.targetValue (cutoff) - 0.5f) < 1.0e-4f);
- CHECK (lasttweak::valueText (song, cutoff, 0.5f) == "1.0 kHz");
- CHECK (lasttweak::valueText (song, { AutomationTargetKind::channelParam, 0, 0, samplerparam::attack }, 0.5f) == "0.200 s");
- // an event lane on the sampler's End binds to the instrument
- auto& p = song.patterns[(std::size_t) song.currentPattern];
- PatternEvents lane;
- lane.target = { AutomationTargetKind::channelParam, 0, 0, samplerparam::end };
- lane.events.push_back ({ 0, 0.5f });
- p.events.push_back (lane);
- auto state = RackState::build (song, nullptr, 48000.0);
- auto bound = false;
- for (const auto& b : state->pluginParams)
- bound = bound || (b.channel == 0 && b.param == samplerparam::end);
- CHECK (bound);
- }
- // Issue #12: a route's level knob (the send knobs under the faders) is an automation target, also when the send sits
- // at 0 (the automation brings it up); moving inserts keeps the target on the same route.
- TEST (issue12_send_level_is_an_automation_target)
- {
- using namespace lynx;
- auto song = Song::makeDefault();
- while (song.mixer.size() < 4)
- song.mixer.emplace_back().name = "Insert " + std::to_string (song.mixer.size());
- song.setRoute (1, 2, true);
- song.setRouteLevel (1, 2, 0.0f);
- const AutomationTarget send { AutomationTargetKind::mixerSend, 1, 2 };
- CHECK (song.targetValue (send) == 0.0f);
- CHECK (song.setTargetValue (send, faderPosition (1.0f)));
- CHECK (std::abs (song.routeLevel (1, 2) - 1.0f) < 1.0e-4f);
- CHECK (lasttweak::valueText (song, send, faderPosition (1.0f)) == "0.0 dB");
- CHECK (song.targetValue ({ AutomationTargetKind::mixerSend, 1, 3 }) < 0.0f); // no such route
- song.setRouteLevel (1, 2, 0.0f);
- auto& p = song.patterns[(std::size_t) song.currentPattern];
- PatternEvents lane;
- lane.target = send;
- lane.events.push_back ({ 0, 0.8f });
- p.events.push_back (lane);
- auto state = RackState::build (song, nullptr, 48000.0);
- auto automated = false;
- for (const auto& in : state->mixerInputs[2])
- automated = automated || (in.source == 1 && in.automation >= 0);
- CHECK (automated);
- mixerops::swapTracks (song, 2, 3);
- CHECK (song.patterns[(std::size_t) song.currentPattern].events.back().target == (AutomationTarget { AutomationTargetKind::mixerSend, 1, 3 }));
- }
- // Crash (0.1.18, the user's crash report): cycling quickly through samples crashed in WaveformCache's disk-cache pruning
- // — std::sort's comparator read each file's access time on every comparison, the times changed during the sort, and
- // the sort ran past the array. The pruning now reads every key once (sortonce::byKey, used by engine/FileSort.h).
- TEST (issue12_sort_reads_each_changing_key_once)
- {
- // a key that changes on every read, like a cache file's access time while other threads read and delete files
- std::vector<int> items;
- for (int i = 0; i < 2000; ++i)
- items.push_back ((i * 7919) % 2000);
- std::vector<int> reads (2000, 0);
- unsigned clock = 12345;
- auto changingKey = [&] (int item) {
- ++reads[(std::size_t) item];
- clock = clock * 1103515245u + 12345u;
- return (long long) (clock >> 8) % 50; // (many ties too)
- };
- std::vector<long long> seen (2000, 0);
- auto recordingKey = [&] (int item) { return seen[(std::size_t) item] = changingKey (item); };
- lynx::sortonce::byKey<int> (items, recordingKey, [] (int a, int b) { return a < b; });
- CHECK (items.size() == 2000);
- CHECK (std::all_of (reads.begin(), reads.end(), [] (int n) { return n == 1; }));
- for (std::size_t i = 1; i < items.size(); ++i)
- {
- const auto a = seen[(std::size_t) items[i - 1]], b = seen[(std::size_t) items[i]];
- CHECK (a < b || (a == b && items[i - 1] < items[i]));
- }
- auto sorted = items;
- std::sort (sorted.begin(), sorted.end());
- for (int i = 0; i < 2000; ++i)
- CHECK (sorted[(std::size_t) i] == i); // nothing lost or duplicated
- // newest first
- std::vector<int> few { 3, 1, 2 };
- lynx::sortonce::byKey<int> (few, [] (int v) { return v * 10; }, [] (int a, int b) { return a < b; }, true);
- CHECK ((few == std::vector<int> { 3, 2, 1 }));
- }
- // Round 165q's find (issue #12, shortcuts): with the Undo history, Settings, Tempo tapper, Quick-add, Audio editor or a
- // plugin / channel window focused, Space, F12 or a user's key did nothing — those windows only knew Esc. The keys they
- // leave unused now run the global actions (as in FL), never a panel's keys, and a focused text field keeps its typing.
- TEST (issue12_secondary_windows_run_the_global_shortcuts)
- {
- using namespace lynx::keys;
- KeyMap map;
- CHECK (map.findFromSecondaryWindow ({ space }, false, false) == "transport.playStop");
- CHECK (map.findFromSecondaryWindow ({ f12 }, false, false) == "view.closeWindows");
- CHECK (map.findFromSecondaryWindow ({ f10 }, false, false) == "view.midiSettings");
- CHECK (map.findFromSecondaryWindow ({ 'M', ctrl }, false, false) == "transport.metronome");
- CHECK (map.findFromSecondaryWindow ({ 'C' }, false, false).empty()); // the Playlist's Knife stays the Playlist's
- CHECK (map.findFromSecondaryWindow ({ escape }, false, false).empty()); // Esc closes the window
- // the user's key for a global action works there too (the 'C' Metronome of the report)
- map.setChords ("transport.metronome", { { 'C' } });
- CHECK (map.findFromSecondaryWindow ({ 'C' }, false, false) == "transport.metronome");
- // typing into a text field: its letters, Space, arrows, Enter are text; F-keys and Ctrl chords still work
- CHECK (map.findFromSecondaryWindow ({ 'C' }, true, false).empty());
- CHECK (map.findFromSecondaryWindow ({ space }, true, false).empty());
- CHECK (map.findFromSecondaryWindow ({ left }, true, false).empty());
- CHECK (map.findFromSecondaryWindow ({ f12 }, true, false) == "view.closeWindows");
- // the typing piano owns its letters
- CHECK (map.findFromSecondaryWindow ({ 'C' }, false, true).empty());
- }
- // Issue #12: an automation clip on the Sampler's Cutoff reaches the sound (setParameter on the audio thread), keeps its
- // value when the song is re-applied unchanged, and lets go when the knob is turned by hand.
- TEST (issue12_sampler_cutoff_automation_changes_the_sound)
- {
- auto data = std::make_shared<lynx::SampleData>();
- data->sampleRate = 48000.0;
- for (int i = 0; i < 6000; ++i)
- data->left.push_back (std::sin (0.6f * (float) i) * 0.25f); // ~4.6 kHz
- lynx::ChannelDef c;
- c.instrument = lynx::InstrumentKind::sampler;
- auto energyOf = [] (lynx::Instrument& sampler) {
- sampler.allNotesOff();
- sampler.noteOn (60, 0.8f);
- std::vector<float> l (4000), r (4000);
- sampler.render (l.data(), r.data(), 4000, 0.7f, 0.7f);
- double e = 0.0;
- for (std::size_t i = 1000; i < l.size(); ++i)
- e += (double) l[i] * l[i];
- return e;
- };
- auto sampler = lynx::makeInstrument (lynx::InstrumentKind::sampler, data);
- sampler->prepare (48000.0);
- sampler->configure (c, 120.0);
- const auto open = energyOf (*sampler);
- sampler->setParameter (lynx::samplerparam::cutoff, 0.0f); // the clip at its bottom: 20 Hz
- const auto automated = energyOf (*sampler);
- sampler->configure (c, 120.0); // the song re-applied unchanged (any edit elsewhere): the automation keeps its value
- const auto kept = energyOf (*sampler);
- c.sampler.cutoff = 19000.0f; // the knob turned by hand
- sampler->configure (c, 120.0);
- const auto byHand = energyOf (*sampler);
- CHECK (open > 1.0);
- CHECK (automated < open * 0.05);
- CHECK (kept < open * 0.05);
- CHECK (byHand > open * 0.5);
- }
|