Пример #1
0
Uuid& Uuid::operator= (const String& uuidString)
{
    MemoryBlock mb;
    mb.loadFromHexString (uuidString);
    mb.ensureSize (sizeof (uuid), true);
    mb.copyTo (uuid, 0, sizeof (uuid));
    return *this;
}
Пример #2
0
void DexedAudioProcessorEditor::storeProgram() {
    String currentName = normalizeSysexName((const char *) processor->data+145);
    char destSysex[4096];
    File *externalFile = NULL;
    
    memcpy(&destSysex, processor->sysex, 4096);

    bool activeCartridgeFound = processor->activeFileCartridge.exists();
    
    while (true) {
        String msg;
        
        if ( externalFile == NULL ) {
            if ( activeCartridgeFound )
                msg = "Store program to current (" + processor->activeFileCartridge.getFileName() + ") / new cartridge";
            else
                msg = "Store program to current / new cartridge";
        } else {
            msg = "Store program to " + externalFile->getFileName();
        }
        
        AlertWindow dialog("Store Program", msg, AlertWindow::NoIcon, this);
        dialog.addTextEditor("Name", currentName, String("Name"), false);
        // TODO: fix the name length to 10

        StringArray programs;
        extractProgramNames((char *) &destSysex, programs);
        dialog.addComboBox("Dest", programs, "Program Destination");


        if ( externalFile == NULL ) {
            StringArray saveAction;
            saveAction.add("Store program to DAW plugin song state");
            saveAction.add("Store program and create a new copy of the .syx cartridge");
            if ( activeCartridgeFound )
                saveAction.add("Store program and overwrite current .syx cartridge");
        
            dialog.addComboBox("SaveAction", saveAction, "Store Action");
        }
                
        dialog.addButton("OK", 0, KeyPress(KeyPress::returnKey));
        dialog.addButton("CANCEL", 1, KeyPress(KeyPress::escapeKey));
        dialog.addButton("EXTERNAL FILE", 2, KeyPress());
        int response = dialog.runModalLoop();

        if ( response == 2 ) {
            FileChooser fc("Destination Sysex", processor->dexedCartDir, "*.syx;*.SYX;*.*", 1);

            if ( fc.browseForFileToOpen() ) {
                if ( externalFile != NULL ) 
                    delete externalFile;

                MemoryBlock block;
                externalFile = new File(fc.getResults().getReference(0));
                if ( externalFile->loadFileAsData(block) ) {
                    block.copyTo(destSysex, 6, 4096);
                    continue;
                }
                AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "Read error", "Unable to read file");
            }
        }

        if ( response == 0 ) {
            TextEditor *name = dialog.getTextEditor("Name");
            ComboBox *dest = dialog.getComboBoxComponent("Dest");
            
            int programNum = dest->getSelectedItemIndex();
            String programName(name->getText());
            if ( programName.length() > 10 ) {
                int toStrip = programName.length() - 10;
                programName = programName.dropLastCharacters(toStrip);
            }

            if ( externalFile == NULL ) {
                packProgram((uint8_t *) processor->sysex, (uint8_t *) processor->data, programNum, programName);
                processor->programNames.set(programNum, programName);
                rebuildProgramCombobox();
                processor->setCurrentProgram(programNum);
                processor->updateHostDisplay();
                
                int action = dialog.getComboBoxComponent("SaveAction")->getSelectedItemIndex();
                if ( action > 0 ) {                  
                    File destination = processor->activeFileCartridge;
                    if ( ! destination.exists() ) {
                        FileChooser fc("Destination Sysex", processor->dexedCartDir, "*.syx", 1);
                        if ( ! fc.browseForFileToSave(true) )
                            break;
                        destination = fc.getResult();
                    }
                    char sysexFile[4104];
                    exportSysexCart((char *) &sysexFile, (char *) &processor->sysex, 0);
                    if ( ! destination.replaceWithData(sysexFile, 4104) ) {
                        AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "Write error", "Unable to write file");
                    }
                    processor->activeFileCartridge = destination;
                }
            } else {
                packProgram((uint8_t *) &destSysex, (uint8_t *) processor->data, programNum, programName);
                char sysexFile[4104];
                exportSysexCart((char *) &sysexFile, (char *) &destSysex, 0);
                if ( ! externalFile->replaceWithData(sysexFile, 4104) ) {
                    AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "Write error", "Unable to write file");
                }
            }
        }
        break;
    }

    if ( externalFile != NULL )
        delete externalFile;
    cartManager.resetActiveSysex();
}