void initialise (const String& commandLine) { // initialise our settings file.. PropertiesFile::Options options; options.applicationName = "Juce Audio Plugin Host"; options.filenameSuffix = "settings"; options.osxLibrarySubFolder = "Preferences"; appProperties = new ApplicationProperties(); appProperties->setStorageParameters (options); commandManager = new ApplicationCommandManager(); AudioPluginFormatManager::getInstance()->addDefaultFormats(); AudioPluginFormatManager::getInstance()->addFormat (new InternalPluginFormat()); mainWindow = new MainHostWindow(); //mainWindow->setUsingNativeTitleBar (true); commandManager->registerAllCommandsForTarget (this); commandManager->registerAllCommandsForTarget (mainWindow); mainWindow->menuItemsChanged(); if (commandLine.isNotEmpty() && mainWindow->getGraphEditor() != 0) { #if JUCE_MAC if (! commandLine.trimStart().startsWith ("-")) #endif mainWindow->getGraphEditor()->graph.loadFrom (File::getCurrentWorkingDirectory() .getChildFile (commandLine), true); } }
void LibraryModule::findAndAddCompiledCode (ProjectExporter& exporter, ProjectSaver& projectSaver, const File& localModuleFolder, Array<File>& result) const { const var compileArray (moduleInfo.moduleInfo ["compile"]); // careful to keep this alive while the array is in use! if (const Array<var>* const files = compileArray.getArray()) { for (int i = 0; i < files->size(); ++i) { const var& file = files->getReference(i); const String filename (file ["file"].toString()); if (filename.isNotEmpty() && fileTargetMatches (exporter, file ["target"].toString())) { const File compiledFile (localModuleFolder.getChildFile (filename)); result.add (compiledFile); Project::Item item (projectSaver.addFileToGeneratedGroup (compiledFile)); if (file ["warnings"].toString().equalsIgnoreCase ("disabled")) item.getShouldInhibitWarningsValue() = true; if (file ["stdcall"]) item.getShouldUseStdCallValue() = true; } } } }
void FileBrowserComponent::comboBoxChanged (ComboBox*) { const String newText (currentPathBox.getText().trim().unquoted()); if (newText.isNotEmpty()) { const int index = currentPathBox.getSelectedId() - 1; StringArray rootNames, rootPaths; getRoots (rootNames, rootPaths); if (rootPaths [index].isNotEmpty()) { setRoot (File (rootPaths [index])); } else { File f (newText); for (;;) { if (f.isDirectory()) { setRoot (f); break; } if (f.getParentDirectory() == f) break; f = f.getParentDirectory(); } } } }
//============================================================================== void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName) { if (defaultMidiOutputName != deviceName) { Array<AudioIODeviceCallback*> oldCallbacks; { const ScopedLock sl (audioCallbackLock); oldCallbacks.swapWith (callbacks); } if (currentAudioDevice != nullptr) for (int i = oldCallbacks.size(); --i >= 0;) oldCallbacks.getUnchecked(i)->audioDeviceStopped(); defaultMidiOutput = nullptr; defaultMidiOutputName = deviceName; if (deviceName.isNotEmpty()) defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName)); if (currentAudioDevice != nullptr) for (int i = oldCallbacks.size(); --i >= 0;) oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice); { const ScopedLock sl (audioCallbackLock); oldCallbacks.swapWith (callbacks); } updateXml(); sendChangeMessage(); } }
void UnitTestRunner::addFail (const String& failureMessage) { { const ScopedLock sl (results.getLock()); TestResult* const r = results.getLast(); jassert (r != 0); // You need to call UnitTest::beginTest() before performing any tests! r->failures++; String message ("!!! Test "); message << (r->failures + r->passes) << " failed"; if (failureMessage.isNotEmpty()) message << ": " << failureMessage; r->messages.add (message); logMessage (message); } resultsUpdated(); if (assertOnFailure) { jassertfalse } }
const Array<Range<int> > CtrlrLuaMethodCodeEditor::searchForMatchesInDocument(CodeDocument &doc, const String &search) { Array<Range<int> > results; int position = -1; lastFoundPosition = -1; do { String documentContent = doc.getAllContent(); if (documentContent.isNotEmpty()) { if (editorComponent->isCaseSensitiveSearch()) { position = documentContent.indexOfIgnoreCase (lastFoundPosition+1, search); } else { position = documentContent.indexOf (lastFoundPosition+1, search); } } if (position >= 0) { lastFoundPosition = position; results.add (Range<int> (lastFoundPosition, lastFoundPosition+search.length())); } else { lastFoundPosition = -1; } } while (lastFoundPosition >= 0); return (results); }
void TooltipWindow::displayTip (Point<int> screenPos, const String& tip) { jassert (tip.isNotEmpty()); if (tipShowing != tip) repaint(); tipShowing = tip; if (Component* const parent = getParentComponent()) { updatePosition (tip, parent->getLocalPoint (nullptr, screenPos), parent->getLocalBounds()); } else { updatePosition (tip, screenPos, Desktop::getInstance().getDisplays() .getDisplayContaining (screenPos).userArea); addToDesktop (ComponentPeer::windowHasDropShadow | ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses); } toFront (false); }
void ComboBox::addSectionHeading (const String& headingName) { // you can't add empty strings to the list.. jassert (headingName.isNotEmpty()); if (headingName.isNotEmpty()) { if (separatorPending) { separatorPending = false; items.add (new ItemInfo (String::empty, 0, false, false)); } items.add (new ItemInfo (headingName, 0, true, true)); } }
//============================================================================== String& GeneratedCode::getCallbackCode (const String& requiredParentClass, const String& returnType, const String& prototype, const bool hasPrePostUserSections) { String parentClass (requiredParentClass); if (parentClass.isNotEmpty() && ! (parentClass.startsWith (T("public ")) || parentClass.startsWith (T("private ")) || parentClass.startsWith (T("protected ")))) { parentClass = T("public ") + parentClass; } for (int i = callbacks.size(); --i >= 0;) { CallbackMethod* const cm = callbacks.getUnchecked(i); if (cm->requiredParentClass == parentClass && cm->returnType == returnType && cm->prototype == prototype) return cm->content; } CallbackMethod* const cm = new CallbackMethod(); callbacks.add (cm); cm->requiredParentClass = parentClass; cm->returnType = returnType; cm->prototype = prototype; cm->hasPrePostUserSections = hasPrePostUserSections; return cm->content; }
void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar, int width, int height, double progress, const String& textToShow) { if (progress < 0 || progress >= 1.0) { LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow); } else { const Colour background (progressBar.findColour (ProgressBar::backgroundColourId)); const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId)); g.fillAll (background); g.setColour (foreground); g.fillRect (1, 1, jlimit (0, width - 2, roundToInt (progress * (width - 2))), height - 2); if (textToShow.isNotEmpty()) { g.setColour (Colour::contrasting (background, foreground)); g.setFont (height * 0.6f); g.drawText (textToShow, 0, 0, width, height, Justification::centred, false); } } }
const String GeneratedCode::getCallbackDefinitions() const { String s; for (int i = 0; i < callbacks.size(); ++i) { CallbackMethod* const cm = callbacks.getUnchecked(i); const String userCodeBlockName (T("User") + makeValidCppIdentifier (cm->prototype.upToFirstOccurrenceOf (T("("), false, false), true, true, false).trim()); if (userCodeBlockName.isNotEmpty() && cm->hasPrePostUserSections) { s << cm->returnType << " " << className << "::" << cm->prototype << "\n{\n //[" << userCodeBlockName << "_Pre]\n //[/" << userCodeBlockName << "_Pre]\n\n " << indentCode (cm->content.trim(), 4) << "\n\n //[" << userCodeBlockName << "_Post]\n //[/" << userCodeBlockName << "_Post]\n}\n\n"; } else { s << cm->returnType << " " << className << "::" << cm->prototype << "\n{\n " << indentCode (cm->content.trim(), 4) << "\n}\n\n"; } } return s; }
bool getIndentForCurrentBlock (CodeDocument::Position pos, const String& tab, String& blockIndent, String& lastLineIndent) { int braceCount = 0; bool indentFound = false; while (pos.getLineNumber() > 0) { pos = pos.movedByLines (-1); const String line (pos.getLineText()); const String trimmedLine (line.trimStart()); braceCount += getBraceCount (trimmedLine.getCharPointer()); if (braceCount > 0) { blockIndent = getLeadingWhitespace (line); if (! indentFound) lastLineIndent = blockIndent + tab; return true; } if ((! indentFound) && trimmedLine.isNotEmpty()) { indentFound = true; lastLineIndent = getLeadingWhitespace (line); } } return false; }
bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList) { String file (filesOrIdentifiersToScan [nextIndex]); if (file.isNotEmpty() && ! list.isListingUpToDate (file)) { OwnedArray <PluginDescription> typesFound; // Add this plugin to the end of the dead-man's pedal list in case it crashes... StringArray crashedPlugins (getDeadMansPedalFile()); crashedPlugins.removeString (file); crashedPlugins.add (file); setDeadMansPedalFile (crashedPlugins); list.scanAndAddFile (file, dontRescanIfAlreadyInList, typesFound, format); // Managed to load without crashing, so remove it from the dead-man's-pedal.. crashedPlugins.removeString (file); setDeadMansPedalFile (crashedPlugins); if (typesFound.size() == 0) failedFiles.add (file); } return skipNextFile(); }
void paintCell (Graphics& g, int row, int columnId, int width, int height, bool /*rowIsSelected*/) override { String text; bool isBlacklisted = row >= list.getNumTypes(); if (isBlacklisted) { if (columnId == nameCol) text = list.getBlacklistedFiles() [row - list.getNumTypes()]; else if (columnId == descCol) text = TRANS("Deactivated after failing to initialise correctly"); } else if (const PluginDescription* const desc = list.getType (row)) { switch (columnId) { case nameCol: text = desc->name; break; case typeCol: text = desc->pluginFormatName; break; case categoryCol: text = desc->category.isNotEmpty() ? desc->category : "-"; break; case manufacturerCol: text = desc->manufacturerName; break; case descCol: text = getPluginDescription (*desc); break; default: jassertfalse; break; } } if (text.isNotEmpty()) { g.setColour (isBlacklisted ? Colours::red : columnId == nameCol ? Colours::black : Colours::grey); g.setFont (Font (height * 0.7f, Font::bold)); g.drawFittedText (text, 4, 0, width - 6, height, Justification::centredLeft, 1, 0.9f); } }
void finish (bool shouldKill) { String result; Array<URL> selection; if (shouldKill) child.kill(); else result = child.readAllProcessOutput().trim(); if (result.isNotEmpty()) { StringArray tokens; if (selectMultipleFiles) tokens.addTokens (result, separator, "\""); else tokens.add (result); for (auto& token : tokens) selection.add (URL (File::getCurrentWorkingDirectory().getChildFile (token))); } if (! shouldKill) { child.waitForProcessToFinish (60 * 1000); owner.finished (selection); } }
//============================================================================== bool File::isAbsolutePath (const String& path) { return path.startsWithChar (separator) #if JUCE_WINDOWS || (path.isNotEmpty() && path[1] == ':'); #else || path.startsWithChar ('~');
void LibraryModule::getLocalCompiledFiles (const File& localModuleFolder, Array<File>& result) const { const var compileArray (moduleInfo.moduleInfo ["compile"]); // careful to keep this alive while the array is in use! if (const Array<var>* const files = compileArray.getArray()) { for (int i = 0; i < files->size(); ++i) { const var& file = files->getReference(i); const String filename (file ["file"].toString()); if (filename.isNotEmpty() #if JUCE_MAC && exporterTargetMatches ("xcode", file ["target"].toString()) #elif JUCE_WINDOWS && exporterTargetMatches ("msvc", file ["target"].toString()) #elif JUCE_LINUX && exporterTargetMatches ("linux", file ["target"].toString()) #endif ) { result.add (localModuleFolder.getChildFile (filename)); } } } }
void ProjectExporter::addVSTFolderToPath (bool isVST3) { const String vstFolder (getVSTPathValue (isVST3).toString()); if (vstFolder.isNotEmpty()) addToExtraSearchPaths (RelativePath (vstFolder, RelativePath::projectFolder), 0); }
void CodeDocument::insert (const String& text, const int insertPos, const bool undoable) { if (text.isNotEmpty()) { if (undoable) { undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos)); } else { Position pos (*this, insertPos); const int firstAffectedLine = pos.getLineNumber(); CodeDocumentLine* const firstLine = lines [firstAffectedLine]; String textInsideOriginalLine (text); if (firstLine != nullptr) { const int index = pos.getIndexInLine(); textInsideOriginalLine = firstLine->line.substring (0, index) + textInsideOriginalLine + firstLine->line.substring (index); } maximumLineLength = -1; Array <CodeDocumentLine*> newLines; CodeDocumentLine::createLines (newLines, textInsideOriginalLine); jassert (newLines.size() > 0); CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0); newFirstLine->lineStartInFile = firstLine != nullptr ? firstLine->lineStartInFile : 0; lines.set (firstAffectedLine, newFirstLine); if (newLines.size() > 1) lines.insertArray (firstAffectedLine + 1, newLines.getRawDataPointer() + 1, newLines.size() - 1); int lineStart = newFirstLine->lineStartInFile; for (int i = firstAffectedLine; i < lines.size(); ++i) { CodeDocumentLine& l = *lines.getUnchecked (i); l.lineStartInFile = lineStart; lineStart += l.lineLength; } checkLastLineStatus(); const int newTextLength = text.length(); for (int i = 0; i < positionsToMaintain.size(); ++i) { CodeDocument::Position& p = *positionsToMaintain.getUnchecked(i); if (p.getPosition() >= insertPos) p.setPosition (p.getPosition() + newTextLength); } listeners.call (&CodeDocument::Listener::codeDocumentTextInserted, text, insertPos); } } }
static void addZenityArgs (StringArray& args, String& separator, const String& title, const File& file, const String& filters, bool isDirectory, bool isSave, bool selectMultipleFiles) { args.add ("zenity"); args.add ("--file-selection"); if (title.isNotEmpty()) args.add ("--title=" + title); if (selectMultipleFiles) { separator = ":"; args.add ("--multiple"); args.add ("--separator=" + separator); } else { if (isDirectory) args.add ("--directory"); if (isSave) args.add ("--save"); } if (filters.isNotEmpty() && filters != "*" && filters != "*.*") { StringArray tokens; tokens.addTokens (filters, ";,|", "\""); for (int i = 0; i < tokens.size(); ++i) args.add ("--file-filter=" + tokens[i]); } if (file.isDirectory()) file.setAsCurrentWorkingDirectory(); else if (file.getParentDirectory().exists()) file.getParentDirectory().setAsCurrentWorkingDirectory(); else File::getSpecialLocation (File::userHomeDirectory).setAsCurrentWorkingDirectory(); if (! file.getFileName().isEmpty()) args.add ("--filename=" + file.getFileName()); // supplying the window ID of the topmost window makes sure that Zenity pops up.. if (uint64 topWindowID = getTopWindowID()) setenv ("WINDOWID", String (topWindowID).toRawUTF8(), true); }
void Graphics::drawTextAsPath (const String& text, const AffineTransform& transform) const { if (text.isNotEmpty()) { GlyphArrangement arr; arr.addLineOfText (context.getFont(), text, 0.0f, 0.0f); arr.draw (*this, transform); } }
void CodeEditorComponent::copy() { newTransaction(); const String selection (document.getTextBetween (selectionStart, selectionEnd)); if (selection.isNotEmpty()) SystemClipboard::copyTextToClipboard (selection); }
//============================================================================== void CodeEditorComponent::insertTextAtCaret (const String& newText) { document.deleteSection (selectionStart, selectionEnd); if (newText.isNotEmpty()) document.insertText (caretPos, newText); scrollToKeepCaretOnScreen(); }
File File::getLinkedTarget() const { String f (getLinkedFile (getFullPathName())); if (f.isNotEmpty()) return getSiblingFile (f); return *this; }
void GeneratedCode::addImageResourceLoader (const String& imageMemberName, const String& resourceName) { privateMemberDeclarations << "Image " << imageMemberName << ";\n"; if (resourceName.isNotEmpty()) constructorCode << imageMemberName << " = ImageCache::getFromMemory (" << resourceName << ", " << resourceName << "Size);\n"; }
static File getFontFile (const String& family, const String& style) { String path ("/system/fonts/" + family); if (style.isNotEmpty()) path << '-' << style; return File (path + ".ttf"); }
//----------------------------------------------------------------------------- // Set //----------------------------------------------------------------------------- void GFXPrimitiveBufferHandle::set(GFXDevice *theDevice, U32 indexCount, U32 primitiveCount, GFXBufferType bufferType, String desc) { StrongRefPtr<GFXPrimitiveBuffer>::operator=( theDevice->allocPrimitiveBuffer(indexCount, primitiveCount, bufferType) ); #ifdef TORQUE_DEBUG if( desc.isNotEmpty() ) getPointer()->mDebugCreationPath = desc; #endif }
void appendText (const AttributedString& text, const Range<int>& stringRange, const Font& font, const Colour& colour) { String stringText (text.getText().substring (stringRange.getStart(), stringRange.getEnd())); String::CharPointerType t (stringText.getCharPointer()); String currentString; int lastCharType = 0; for (;;) { const juce_wchar c = t.getAndAdvance(); if (c == 0) break; int charType; if (c == '\r' || c == '\n') charType = 0; else if (CharacterFunctions::isWhitespace (c)) charType = 2; else charType = 1; if (charType == 0 || charType != lastCharType) { if (currentString.isNotEmpty()) tokens.add (new Token (currentString, font, colour, lastCharType == 2 || lastCharType == 0)); currentString = String::charToString (c); if (c == '\r' && *t == '\n') currentString += t.getAndAdvance(); } else { currentString += c; } lastCharType = charType; } if (currentString.isNotEmpty()) tokens.add (new Token (currentString, font, colour, lastCharType == 2)); }
File DataPath::resolvePath (const String& path) { jassert (path.isNotEmpty()); jassert (! File::isAbsolutePath (path)); if (path.substring (0, 1) != "/") return factoryContentPath().getChildFile (path); File file (path); return file; }
void ScopeSync::changeConfiguration(int uid) { if (uid != 0) { String fileName = UserSettings::getInstance()->getConfigurationFilePathFromUID(uid); if (fileName.isNotEmpty()) configurationChanges.add(fileName); } }