Copy Paste functionality
This commit is contained in:
parent
ec75ce6362
commit
7545b20f74
4 changed files with 99 additions and 6 deletions
|
@ -863,6 +863,8 @@ void ObxdAudioProcessorEditor::rebuildComponents (ObxdAudioProcessor& ownerFilte
|
|||
|
||||
void ObxdAudioProcessorEditor::createMenu ()
|
||||
{
|
||||
bool enablePasteOption = macPasteboard::containsPresetData(); // Check if the clipboard contains data for a Preset
|
||||
|
||||
popupMenus.clear();
|
||||
PopupMenu* menu = new PopupMenu();
|
||||
//menu->setLookAndFeel(new CustomLookAndFeel(&this->processor));
|
||||
|
@ -926,6 +928,18 @@ void ObxdAudioProcessorEditor::createMenu ()
|
|||
true,
|
||||
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),
|
||||
"Delete Bank...",
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ enum MenuAction
|
|||
DeletePreset,
|
||||
DeleteBank,
|
||||
ShowBanks,
|
||||
CopyPreset,
|
||||
PastePreset,
|
||||
LoadBank // LoadBank must be the last enum value
|
||||
};
|
||||
//==============================================================================
|
||||
|
|
|
@ -508,12 +508,38 @@ void ObxdAudioProcessor::saveBank() {
|
|||
}
|
||||
|
||||
bool ObxdAudioProcessor::loadPreset(const File& fxpFile) {
|
||||
loadFromFXBFile(fxpFile);
|
||||
loadFromFXPFile(fxpFile);
|
||||
currentPreset = fxpFile.getFileName();
|
||||
currentPresetFile = fxpFile;
|
||||
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){
|
||||
//auto xml = std::unique_ptr<juce::XmlElement>(new juce::XmlElement(""));
|
||||
juce::MemoryBlock m, memoryBlock;
|
||||
|
@ -612,12 +638,40 @@ bool ObxdAudioProcessor::saveFXBFile(const File& fxbFile) {
|
|||
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)
|
||||
{
|
||||
MemoryBlock mb;
|
||||
if (! fxbFile.loadFileAsData(mb))
|
||||
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 size_t dataSize = mb.getSize();
|
||||
|
||||
|
@ -706,10 +760,6 @@ bool ObxdAudioProcessor::loadFromFXBFile(const File& fxbFile)
|
|||
return false;
|
||||
}
|
||||
|
||||
currentBank = fxbFile.getFileName();
|
||||
currentBankFile = fxbFile;
|
||||
updateHostDisplay();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,11 +177,14 @@ public:
|
|||
bool deleteBank();
|
||||
bool loadPreset(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 newPreset(const String &name);
|
||||
void deletePreset();
|
||||
|
||||
bool loadFromFXPFile(const File& fxbFile);
|
||||
bool loadFromFXBFile(const File& fxbFile);
|
||||
bool loadFromMemoryBlock(MemoryBlock& memoryBlock);
|
||||
bool saveFXBFile(const File& fxbFile);
|
||||
bool saveFXPFile(const File& fxpFile);
|
||||
bool saveBank(const File& fxbFile);
|
||||
|
|
Loading…
Reference in a new issue