Skip to content

Commit 5e8b686

Browse files
authored
Merge pull request #1136 from kushview/midi-program-table
node panel: add listing of Midi Programs to view.
2 parents 0e9c32d + 3163e5f commit 5e8b686

5 files changed

Lines changed: 327 additions & 18 deletions

File tree

‎include/element/processor.hpp‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,29 @@ class Processor : public juce::ReferenceCountedObject {
346346
void getMidiProgramsState (juce::String& state) const;
347347

348348
/** Load all MIDI program states to be stored on the node.
349-
349+
350350
@param state The state to set. If this is empty, the midi programs
351351
on the node will be cleared.
352352
*/
353353
void setMidiProgramsState (const juce::String& state);
354354

355+
/** Lightweight description of one saved MIDI program. */
356+
struct MidiProgramInfo {
357+
int program; ///< Zero-based program index (0-127)
358+
juce::String name; ///< Program name
359+
};
360+
361+
/** Returns the saved MIDI programs for this node.
362+
363+
Follows the current mode: when useGlobalMidiPrograms() is true the
364+
global program files on disk are enumerated, otherwise the local
365+
in-memory programs are returned. The result is sorted ascending by
366+
program number.
367+
368+
@return the saved MIDI programs
369+
*/
370+
juce::Array<MidiProgramInfo> getMidiPrograms() const;
371+
355372
//=========================================================================
356373
inline void setMidiChannels (const juce::BigInteger& ch)
357374
{

‎src/engine/processor.cpp‎

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,18 +490,54 @@ Processor::MidiProgram* Processor::getMidiProgram (int program) const
490490
return ret;
491491
}
492492

493+
Array<Processor::MidiProgramInfo> Processor::getMidiPrograms() const
494+
{
495+
Array<MidiProgramInfo> result;
496+
497+
if (useGlobalMidiPrograms())
498+
{
499+
PluginDescription desc;
500+
getPluginDescription (desc);
501+
const auto uids = desc.createIdentifierString();
502+
if (uids.isEmpty())
503+
return result;
504+
505+
const auto dir = DataPath::defaultGlobalMidiProgramsDir();
506+
for (const auto& file : dir.findChildFiles (File::findFiles, false, uids + "_*.eln"))
507+
{
508+
// Filenames are "<uids>_<NNN>.eln"; parse the trailing program index.
509+
const auto index = file.getFileNameWithoutExtension()
510+
.fromLastOccurrenceOf ("_", false, false)
511+
.getIntValue();
512+
if (isPositiveAndBelow (index, 128))
513+
{
514+
String name ("Global ");
515+
name << (index + 1);
516+
result.add ({ index, name });
517+
}
518+
}
519+
}
520+
else
521+
{
522+
// Only include programs that actually have saved state. Reading a
523+
// program name elsewhere can find-or-create empty placeholder entries.
524+
for (auto* const p : midiPrograms)
525+
if (p->state.getSize() > 0)
526+
result.add ({ p->program, p->name });
527+
}
528+
529+
std::sort (result.begin(), result.end(), [] (const MidiProgramInfo& a, const MidiProgramInfo& b) {
530+
return a.program < b.program;
531+
});
532+
533+
return result;
534+
}
535+
493536
void Processor::MidiProgramLoader::handleAsyncUpdate()
494537
{
495538
const File programFile = node.getMidiProgramFile();
496539
const bool globalPrograms = node.useGlobalMidiPrograms();
497540
const auto requestedProgram = node.getMidiProgram();
498-
#if 0
499-
if (node.lastMidiProgram.get() == requestedProgram)
500-
{
501-
DBG("[element] same program, not loading.");
502-
return;
503-
}
504-
#endif
505541

506542
if (globalPrograms)
507543
{

0 commit comments

Comments
 (0)