2
0
Fork 0

Copy Paste functionality

This commit is contained in:
George Reales 2022-10-04 19:30:58 +02:00
parent ec75ce6362
commit 7545b20f74
4 changed files with 99 additions and 6 deletions

View File

@ -863,6 +863,8 @@ void ObxdAudioProcessorEditor::rebuildComponents (ObxdAudioProcessor& ownerFilte
void ObxdAudioProcessorEditor::createMenu () void ObxdAudioProcessorEditor::createMenu ()
{ {
bool enablePasteOption = macPasteboard::containsPresetData(); // Check if the clipboard contains data for a Preset
popupMenus.clear(); popupMenus.clear();
PopupMenu* menu = new PopupMenu(); PopupMenu* menu = new PopupMenu();
//menu->setLookAndFeel(new CustomLookAndFeel(&this->processor)); //menu->setLookAndFeel(new CustomLookAndFeel(&this->processor));
@ -926,7 +928,19 @@ void ObxdAudioProcessorEditor::createMenu ()
true, true,
false); false);
/* fileMenu.addSeparator();
fileMenu.addItem(static_cast<int>(MenuAction::CopyPreset),
"Copy Preset...",
true,
false);
fileMenu.addItem(static_cast<int>(MenuAction::PastePreset),
"Paste Preset...",
enablePasteOption,
false);
/*
fileMenu.addItem(static_cast<int>(MenuAction::DeleteBank), fileMenu.addItem(static_cast<int>(MenuAction::DeleteBank),
"Delete Bank...", "Delete Bank...",
true, true,
@ -1324,6 +1338,30 @@ void ObxdAudioProcessorEditor::MenuActionCallback(int action){
} }
}; };
// Copy to clipboard
if (action == MenuAction::CopyPreset)
{
juce::MemoryBlock serializedData;
// Serialize the Preset, produces the same data as an export but into memory instead of a file.
processor.serializePreset(serializedData);
// Place the data onto the clipboard
macPasteboard::copyPresetDataToClipboard(serializedData.getData(), serializedData.getSize());
}
// Paste from clipboard
if (action == MenuAction::PastePreset)
{
juce::MemoryBlock memoryBlock;
// Fetch Preset data from the clipboard
if (macPasteboard::fetchPresetDataFromClipboard(memoryBlock))
{
// Load the data
processor.loadFromMemoryBlock(memoryBlock); //loadPreset(memoryBlock);
}
}
} }

View File

@ -43,6 +43,8 @@ enum MenuAction
DeletePreset, DeletePreset,
DeleteBank, DeleteBank,
ShowBanks, ShowBanks,
CopyPreset,
PastePreset,
LoadBank // LoadBank must be the last enum value LoadBank // LoadBank must be the last enum value
}; };
//============================================================================== //==============================================================================

View File

@ -508,12 +508,38 @@ void ObxdAudioProcessor::saveBank() {
} }
bool ObxdAudioProcessor::loadPreset(const File& fxpFile) { bool ObxdAudioProcessor::loadPreset(const File& fxpFile) {
loadFromFXBFile(fxpFile); loadFromFXPFile(fxpFile);
currentPreset = fxpFile.getFileName(); currentPreset = fxpFile.getFileName();
currentPresetFile = fxpFile; currentPresetFile = fxpFile;
return true; return true;
} }
/// Serialize the current Preset, just like the saveFXPFile function,
/// but keeps the data in memory instead of writing it to a file.
void ObxdAudioProcessor::serializePreset(MemoryBlock& memoryBlock)
{
juce::MemoryBlock m;
getCurrentProgramStateInformation(m);
{
memoryBlock.reset();
auto totalLen = sizeof (fxProgramSet) + m.getSize() - 8;
memoryBlock.setSize (totalLen, true);
auto set = static_cast<fxProgramSet*>(memoryBlock.getData());
set->chunkMagic = fxbName ("CcnK");
set->byteSize = 0;
set->fxMagic = fxbName ("FPCh");
set->version = fxbSwap (fxbVersionNum);
set->fxID = fxbName ("Obxd");
set->fxVersion = fxbSwap (fxbVersionNum);
set->numPrograms = fxbSwap (getNumPrograms());
programs.currentProgramPtr->name.copyToUTF8(set->name, 28);
set->chunkSize = fxbSwap (static_cast<int32>(m.getSize()));
m.copyTo (set->chunk, 0, m.getSize());
}
}
bool ObxdAudioProcessor::saveFXPFile(const File& fxpFile){ bool ObxdAudioProcessor::saveFXPFile(const File& fxpFile){
//auto xml = std::unique_ptr<juce::XmlElement>(new juce::XmlElement("")); //auto xml = std::unique_ptr<juce::XmlElement>(new juce::XmlElement(""));
juce::MemoryBlock m, memoryBlock; juce::MemoryBlock m, memoryBlock;
@ -612,12 +638,40 @@ bool ObxdAudioProcessor::saveFXBFile(const File& fxbFile) {
return true; return true;
} }
bool ObxdAudioProcessor::loadFromFXPFile(const File& fxpFile)
{
MemoryBlock mb;
if (! fxpFile.loadFileAsData(mb))
return false;
if (!loadFromMemoryBlock(mb))
return false;
currentPreset = fxpFile.getFileName();
currentPresetFile = fxpFile;
updateHostDisplay();
return true;
}
bool ObxdAudioProcessor::loadFromFXBFile(const File& fxbFile) bool ObxdAudioProcessor::loadFromFXBFile(const File& fxbFile)
{ {
MemoryBlock mb; MemoryBlock mb;
if (! fxbFile.loadFileAsData(mb)) if (! fxbFile.loadFileAsData(mb))
return false; return false;
if (!loadFromMemoryBlock(mb))
return false;
currentBank = fxbFile.getFileName();
currentBankFile = fxbFile;
updateHostDisplay();
return true;
}
bool ObxdAudioProcessor::loadFromMemoryBlock(MemoryBlock& mb)
{
const void* const data = mb.getData(); const void* const data = mb.getData();
const size_t dataSize = mb.getSize(); const size_t dataSize = mb.getSize();
@ -706,10 +760,6 @@ bool ObxdAudioProcessor::loadFromFXBFile(const File& fxbFile)
return false; return false;
} }
currentBank = fxbFile.getFileName();
currentBankFile = fxbFile;
updateHostDisplay();
return true; return true;
} }

View File

@ -177,11 +177,14 @@ public:
bool deleteBank(); bool deleteBank();
bool loadPreset(const File& fxpFile); bool loadPreset(const File& fxpFile);
bool savePreset(const File& fxpFile); bool savePreset(const File& fxpFile);
void serializePreset(MemoryBlock& memoryBlock); // Copy the current Preset into a MemoryBlock
void changePresetName(const String &name); void changePresetName(const String &name);
void newPreset(const String &name); void newPreset(const String &name);
void deletePreset(); void deletePreset();
bool loadFromFXPFile(const File& fxbFile);
bool loadFromFXBFile(const File& fxbFile); bool loadFromFXBFile(const File& fxbFile);
bool loadFromMemoryBlock(MemoryBlock& memoryBlock);
bool saveFXBFile(const File& fxbFile); bool saveFXBFile(const File& fxbFile);
bool saveFXPFile(const File& fxpFile); bool saveFXPFile(const File& fxpFile);
bool saveBank(const File& fxbFile); bool saveBank(const File& fxbFile);