From 6cbc19e09e4ac0cd9bd0d20c475f4cf542c342eb Mon Sep 17 00:00:00 2001 From: Dan Stroud Date: Wed, 28 Aug 2024 13:11:27 -0500 Subject: [PATCH 1/2] minor fixes - moved creation of note_players and aliasing of nb.players to nb:init() to resolve error launching nb.lua demo script multiple times. - fixed issue with description>>name field not being populated with MIDI v port name - fixed typo in `voice_mod_targets` - modified sorting of players to handle uppercase names - added nb:stop_all() to cleanup() fn in nb.lua --- lib/nb.lua | 22 ++++++++++++---------- lib/player.lua | 2 +- nb.lua | 4 ++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/nb.lua b/lib/nb.lua index a67ea3f..763f015 100644 --- a/lib/nb.lua +++ b/lib/nb.lua @@ -2,14 +2,6 @@ local mydir = debug.getinfo(1).source:match("@?" .. _path.code .. "(.*/)") local player_lib = include(mydir .. "player") local nb = {} -if note_players == nil then - note_players = {} -end - --- note_players is a global that you can add note-players to from anywhere before --- you call nb:add_param. -nb.players = note_players -- alias the global here. Helps with standalone use. - nb.none = player_lib:new() -- Set this before init() to affect the number of voices added for some mods. @@ -92,7 +84,7 @@ local function add_midi_players() mod_d = "cc " .. params:get("midi_modulation_cc_" .. i .. '_' .. j) end return { - name = "v.name", + name = v.name, supports_bend = true, supports_slew = false, note_mod_targets = { "pressure" }, @@ -109,6 +101,14 @@ end -- Call from your init method. function nb:init() + if note_players == nil then + note_players = {} + end + + -- note_players is a global that you can add note-players to from anywhere before + -- you call nb:add_param. + nb.players = note_players -- alias the global here. Helps with standalone use. + nb_player_refcounts = {} add_midi_players() self:stop_all() @@ -122,7 +122,9 @@ function nb:add_param(param_id, param_name) for name, _ in pairs(note_players) do table.insert(names, name) end - table.sort(names) + table.sort(names, function(a, b) + return string.lower(a) < string.lower(b) + end) table.insert(names, 1, "none") local names_inverted = tab.invert(names) params:add_option(param_id, param_name, names, 1) diff --git a/lib/player.lua b/lib/player.lua index eceb9e4..00158a2 100644 --- a/lib/player.lua +++ b/lib/player.lua @@ -76,7 +76,7 @@ function player:describe() supports_slew = false, modulate_description = "unsupported", note_mod_targets = {}, - voice_mod_tarets = {}, + voice_mod_targets = {}, params = {}, } end diff --git a/nb.lua b/nb.lua index 532a0d2..89687f7 100644 --- a/nb.lua +++ b/nb.lua @@ -50,4 +50,8 @@ function grid_redraw() end end g:refresh() +end + +function cleanup() + nb:stop_all() end \ No newline at end of file From d5a8dc8dfd0ec27283159af65ccd9a516ad83de0 Mon Sep 17 00:00:00 2001 From: Dan Stroud Date: Thu, 5 Sep 2024 18:41:32 -0500 Subject: [PATCH 2/2] force text param to string - When saving and loading a pset, text params can be inadvertently converted from strings to numbers. - This results in a player name like "1.1" being added to nb_player_refcounts with a num index rather than string index, preventing the player:active()/inactive() functions from firing as expected. - This fix just forces the text param value to always be a string. --- lib/nb.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/nb.lua b/lib/nb.lua index 763f015..36694ca 100644 --- a/lib/nb.lua +++ b/lib/nb.lua @@ -134,7 +134,7 @@ function nb:add_param(param_id, param_name) local p = params:lookup_param(param_id) local initialized = false function p:get_player() - local name = params:get(string_param_id) + local name = tostring(params:get(string_param_id)) if name == "none" then if p.player ~= nil then p.player:count_down() @@ -161,7 +161,7 @@ function nb:add_param(param_id, param_name) initialized = true end, p) params:set_action(string_param_id, function(name_param) - local i = names_inverted[params:get(string_param_id)] + local i = names_inverted[tostring(params:get(string_param_id))] if i ~= nil then -- silently set the interface param. params:set(param_id, i, true)