Пример #1
0
LinkedList getVst2xPluginLocations(CharString currentDirectory) {
  LinkedList locations = newLinkedList();
  CharString locationBuffer;
  const char* programFiles = (!isExecutable64Bit() && isHost64Bit()) ?
    kPlatformWindows32BitProgramFolder : kPlatformWindowsProgramFolder;

  linkedListAppend(locations, currentDirectory);

  locationBuffer = newCharString();
  snprintf(locationBuffer->data, (size_t)(locationBuffer->length), "C:\\VstPlugins");
  linkedListAppend(locations, locationBuffer);

  locationBuffer = newCharString();
  snprintf(locationBuffer->data, (size_t)(locationBuffer->length), "%s\\VstPlugIns", programFiles);
  linkedListAppend(locations, locationBuffer);

  locationBuffer = newCharString();
  snprintf(locationBuffer->data, (size_t)(locationBuffer->length), "%s\\Common Files\\VstPlugIns", programFiles);
  linkedListAppend(locations, locationBuffer);

  locationBuffer = newCharString();
  snprintf(locationBuffer->data, (size_t)(locationBuffer->length), "%s\\Steinberg\\VstPlugIns", programFiles);
  linkedListAppend(locations, locationBuffer);

  return locations;
}
Пример #2
0
static int _testNewFileWithRelativePath(void) {
  CharString p = newCharString();
  sprintf(p->data, "%s%c%s", "test", PATH_DELIMITER, "file");
  CharString pAbs = newCharString();
  sprintf(p->data, "%s%s%c%s%c%s", ROOT_DIRECTORY, get);
  freeCharString(p);
  return 0;
}
Пример #3
0
static int _testBuildAbsolutePathNullPath(void) {
  CharString f = newCharString();
  CharString out = newCharString();

  buildAbsolutePath(NULL, f, NULL, out);
  assert(charStringIsEmpty(out));

  freeCharString(f);
  freeCharString(out);
  return 0;
}
Пример #4
0
ErrorReporter newErrorReporter(void) {
  ErrorReporter errorReporter = (ErrorReporter)malloc(sizeof(ErrorReporterMembers));

  errorReporter->started = false;
  errorReporter->completed = false;
  errorReporter->reportName = newCharString();

  errorReporter->desktopPath = newCharString();
  errorReporter->reportDirPath = newCharString();

  return errorReporter;
}
Пример #5
0
static int _testBuildAbsolutePathEmptyPath(void) {
  CharString d = newCharString();
  CharString f = newCharStringWithCString(TEST_FILENAME);
  CharString out = newCharString();

  buildAbsolutePath(d, f, NULL, out);
  assert(charStringIsEmpty(out));

  freeCharString(d);
  freeCharString(f);
  freeCharString(out);
  return 0;
}
Пример #6
0
static int _testBuildAbsolutePathEmptyFile(void) {
  CharString d = getCurrentDirectory();
  CharString f = newCharString();
  CharString out = newCharString();

  buildAbsolutePath(d, f, NULL, out);
  assert(charStringIsEmpty(out));

  freeCharString(d);
  freeCharString(f);
  freeCharString(out);
  return 0;
}
Пример #7
0
static int _testPluginFactoryEmptyPluginName(void)
{
    CharString invalid = newCharString();
    CharString pluginRoot = newCharString();
    Plugin p = pluginFactory(invalid, pluginRoot);

    assertIsNull(p);

    freeCharString(invalid);
    freeCharString(pluginRoot);
    freePlugin(p);
    return 0;
}
Пример #8
0
static int _testNewFileWithAbsolutePath(void) {
  CharString p = newCharString();
  sprintf(p->data, "%s%c%s", "test", PATH_DELIMITER, "file");
  freeCharString(c);
  
  return 0;
}
Пример #9
0
static int _testAppendItemToNullList(void) {
  CharString c = newCharString();
  // The test here is not to crash
  linkedListAppend(NULL, c);
  freeCharString(c);
  return 0;
}
Пример #10
0
static int _testRunWithNoPlugins(const char *testName,
                                 const CharString applicationPath,
                                 const CharString resourcesPath) {
  return runIntegrationTest(testName, newCharString(),
                            RETURN_CODE_INVALID_PLUGIN_CHAIN, kTestOutputNone,
                            applicationPath, resourcesPath);
}
Пример #11
0
char *stringForLastError(int errorNumber)
{
    EventLogger eventLogger = _getEventLoggerInstance();

    if (eventLogger->systemErrorMessage == NULL) {
        eventLogger->systemErrorMessage = newCharString();
    }

#if UNIX
    return strerror(errorNumber);
#elif WINDOWS
    FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
                   0,
                   errorNumber,
                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                   eventLogger->systemErrorMessage->data,
                   (DWORD)(eventLogger->systemErrorMessage->capacity - 1),
                   NULL);
    // Windows adds newlines for error messages which we must trim
    char *searchChar = strrchr(eventLogger->systemErrorMessage->data, '\n');
    if (searchChar != NULL) {
        *searchChar = '\0';
    }
    searchChar = strrchr(eventLogger->systemErrorMessage->data, '\r');
    if (searchChar != NULL) {
        *searchChar = '\0';
    }
    return eventLogger->systemErrorMessage->data;
#endif

}
Пример #12
0
LinkedList getVst2xPluginLocations(CharString currentDirectory) {
  LinkedList locations = newLinkedList();
  CharString locationBuffer;

  linkedListAppend(locations, currentDirectory);

  locationBuffer = newCharString();
  snprintf(locationBuffer->data, (size_t)(locationBuffer->capacity), "/Library/Audio/Plug-Ins/VST");
  linkedListAppend(locations, locationBuffer);

  locationBuffer = newCharString();
  snprintf(locationBuffer->data, (size_t)(locationBuffer->capacity), "%s/Library/Audio/Plug-Ins/VST", getenv("HOME"));
  linkedListAppend(locations, locationBuffer);

  return locations;
}
Пример #13
0
// This could live in File, however this is currently the only place it is being
// used
// and also it's a rather cheap hack, so I would prefer to keep it as a static
// function
// here until another use-case presents itself. If that should happen, then we
// should
// refactor this code properly and move it to File.
static boolByte _copyDirectoryToErrorReportDir(ErrorReporter self,
                                               CharString path) {
  boolByte success;

#if UNIX
  int result;
  CharString copyCommand = newCharString();
  // TODO: This is the lazy way of doing this...
  snprintf(copyCommand->data, copyCommand->capacity, "/bin/cp -r \"%s\" \"%s\"",
           path->data, self->reportDirPath->data);
  result = system(copyCommand->data);
  success = (boolByte)(WEXITSTATUS(result) == 0);

  if (!success) {
    logError("Could not copy '%s' to '%s'\n", path->data,
             self->reportDirPath->data);
  }

#else
  logUnsupportedFeature("Copy directory recursively");
  success = false;
#endif

  return success;
}
Пример #14
0
static int _testBuildAbsolutePathWithFileExtensionTwice(void) {
  CharString d = newCharStringWithCString(ROOT_DIRECTORY);
  CharString out = newCharString();
  CharString f = newCharStringWithCString(TEST_FILENAME);
  CharString expected = newCharString();

  snprintf(expected->data, expected->capacity, "%s%c%s", ROOT_DIRECTORY, PATH_DELIMITER, TEST_FILENAME);
  buildAbsolutePath(d, f, "txt", out);
  assertCharStringEquals(out, expected->data);

  freeCharString(d);
  freeCharString(out);
  freeCharString(f);
  freeCharString(expected);
  return 0;
}
Пример #15
0
SampleSource newSampleSourcePcm(const CharString sampleSourceName) {
    SampleSource sampleSource = (SampleSource)malloc(sizeof(SampleSourceMembers));
    SampleSourcePcmData extraData = (SampleSourcePcmData)malloc(sizeof(SampleSourcePcmDataMembers));

    sampleSource->sampleSourceType = SAMPLE_SOURCE_TYPE_PCM;
    sampleSource->openedAs = SAMPLE_SOURCE_OPEN_NOT_OPENED;
    sampleSource->sourceName = newCharString();
    charStringCopy(sampleSource->sourceName, sampleSourceName);
    sampleSource->numSamplesProcessed = 0;

    sampleSource->openSampleSource = openSampleSourcePcm;
    sampleSource->readSampleBlock = readBlockFromPcmFile;
    sampleSource->writeSampleBlock = writeBlockToPcmFile;
    sampleSource->closeSampleSource = _closeSampleSourcePcm;
    sampleSource->freeSampleSourceData = freeSampleSourceDataPcm;

    extraData->isStream = false;
    extraData->isLittleEndian = true;
    extraData->fileHandle = NULL;
    extraData->dataBufferNumItems = 0;
    extraData->interlacedPcmDataBuffer = NULL;

    extraData->numChannels = (unsigned short)getNumChannels();
    extraData->sampleRate = (unsigned int)getSampleRate();
    extraData->bitsPerSample = 16;
    sampleSource->extraData = extraData;

    return sampleSource;
}
Пример #16
0
SampleSource _newSampleSourceWave(const CharString sampleSourceName)
{
    SampleSource sampleSource = (SampleSource)malloc(sizeof(SampleSourceMembers));
    SampleSourcePcmData extraData = (SampleSourcePcmData)malloc(sizeof(SampleSourcePcmDataMembers));

    sampleSource->sampleSourceType = SAMPLE_SOURCE_TYPE_WAVE;
    sampleSource->openedAs = SAMPLE_SOURCE_OPEN_NOT_OPENED;
    sampleSource->sourceName = newCharString();
    charStringCopy(sampleSource->sourceName, sampleSourceName);
    sampleSource->numSamplesProcessed = 0;

    sampleSource->openSampleSource = _openSampleSourceWave;
    sampleSource->readSampleBlock = _readBlockFromWaveFile;
    sampleSource->writeSampleBlock = _writeBlockToWaveFile;
    sampleSource->closeSampleSource = _closeSampleSourceWave;
    sampleSource->freeSampleSourceData = freeSampleSourceDataPcm;

    extraData->isStream = false;
    extraData->isLittleEndian = true;
    extraData->fileHandle = NULL;
    // Assume default values for these items. However, if an incoming SampleBuffer
    // has different values for the channel count or blocksize, then we will reassign
    // based on those values.
    extraData->dataBufferNumItems = getNumChannels() * getBlocksize();
    extraData->pcmSampleBuffer = newPcmSampleBuffer(getNumChannels(), getBlocksize(), getBitDepth());

    extraData->numChannels = (unsigned short)getNumChannels();
    extraData->sampleRate = (unsigned int)getSampleRate();
    extraData->bitDepth = kBitDepthDefault;

    sampleSource->extraData = extraData;
    return sampleSource;
}
Пример #17
0
boolByte removeDirectory(const CharString absolutePath) {
  boolByte result = false;

#if UNIX
  if(!fileExists(absolutePath->data)) {
    return false;
  }

  // This is a bit lazy, perhaps...
  CharString removeCommand = newCharString();
  snprintf(removeCommand->data, removeCommand->length, "/bin/rm -rf \"%s\"", absolutePath->data);
  result = system(removeCommand->data);
  freeCharString(removeCommand);
  return (result == 0);
#elif WINDOWS
  SHFILEOPSTRUCTA fileOperation = {0};
  fileOperation.wFunc = FO_DELETE;
  fileOperation.pFrom = absolutePath->data;
  fileOperation.fFlags = FOF_NO_UI;
  return (SHFileOperationA(&fileOperation) == 0);
#else
  logUnsupportedFeature("Copy directory recursively");
  return false;
#endif
}
Пример #18
0
Plugin newPluginMock(void) {
  Plugin plugin = (Plugin)malloc(sizeof(PluginMembers));
  PluginMockData extraData = (PluginMockData)malloc(sizeof(PluginMockDataMembers));

  plugin->interfaceType = PLUGIN_TYPE_INTERNAL;
  plugin->pluginType = PLUGIN_TYPE_INSTRUMENT;
  plugin->pluginName = newCharStringWithCString("Mock");
  plugin->pluginLocation = newCharString();
  charStringCopyCString(plugin->pluginLocation, "Internal");

  plugin->openPlugin = _pluginMockOpen;
  plugin->displayInfo = _pluginMockEmpty;
  plugin->getAbsolutePath = _pluginMockGetAbsolutePath;
  plugin->getSetting = _pluginMockGetSetting;
  plugin->prepareForProcessing = _pluginMockPrepareForProcessing;
  plugin->processAudio = _pluginMockProcessAudio;
  plugin->processMidiEvents = _pluginMockProcessMidiEvents;
  plugin->setParameter = _pluginMockSetParameter;
  plugin->closePlugin = _pluginMockClose;
  plugin->freePluginData = _pluginMockEmpty;

  extraData->isOpen = false;
  extraData->isPrepared = false;
  extraData->processAudioCalled = false;
  extraData->processMidiCalled = false;
  plugin->extraData = extraData;

  return plugin;
}
Пример #19
0
ProgramOption newProgramOptionWithName(const int optionIndex, const char* name,
  const char* help, boolByte hasShortForm, ProgramOptionType type,
  ProgramOptionArgumentType argumentType) {
  ProgramOption option = (ProgramOption)malloc(sizeof(ProgramOptionMembers));

  option->index = optionIndex;
  option->name = newCharStringWithCString(name);
  option->help = newCharStringWithCString(help);
  option->hasShortForm = hasShortForm;
  option->hideInHelp = false;

  option->type = type;
  switch(type) {
    case kProgramOptionTypeEmpty:
      // Nothing needed here
      break;
    case kProgramOptionTypeString:
      option->_data.string = newCharString();
      break;
    case kProgramOptionTypeNumber:
      option->_data.number = 0.0f;
      break;
    case kProgramOptionTypeList:
      option->_data.list = newLinkedList();
      break;
    default:
      logInternalError("ProgramOption with invalid type");
      break;
  }
  option->argumentType = argumentType;
  option->enabled = false;

  return option;
}
Пример #20
0
// Note that this method skips hidden files
LinkedList listDirectory(const CharString directory) {
  LinkedList items = newLinkedList();
  CharString filename;

#if UNIX
  DIR* directoryPtr = opendir(directory->data);
  if(directoryPtr == NULL) {
    freeLinkedList(items);
    return 0;
  }
  struct dirent* entry;
  while((entry = readdir(directoryPtr)) != NULL) {
    if(entry->d_name[0] != '.') {
      filename = newCharStringWithCString(entry->d_name);
      linkedListAppend(items, filename);
    }
  }
  closedir(directoryPtr);

#elif WINDOWS
  WIN32_FIND_DATAA findData;
  HANDLE findHandle;
  CharString searchString = newCharString();

  snprintf(searchString->data, searchString->length, "%s\\*", directory->data);
  findHandle = FindFirstFileA((LPCSTR)(searchString->data), &findData);
  freeCharString(searchString);
  if(findHandle == INVALID_HANDLE_VALUE) {
    freeLinkedList(items);
    return 0;
  }
  do {
    if(findData.cFileName[0] != '.') {
      filename = newCharString();
      strncpy(filename->data, findData.cFileName, filename->length);
      linkedListAppend(items, filename);
    }
  } while(FindNextFileA(findHandle, &findData) != 0);

  FindClose(findHandle);

#else
  logUnsupportedFeature("List directory contents");
#endif

  return items;
}
Пример #21
0
static int _testGuessSampleSourceTypeEmpty(void) {
  CharString empty = newCharString();
  SampleSource s = sampleSourceFactory(empty);
  assertIntEquals(SAMPLE_SOURCE_TYPE_SILENCE, s->sampleSourceType);
  freeSampleSource(s);
  freeCharString(empty);
  return 0;
}
Пример #22
0
static void _remapFileToErrorReportRelativePath(void* item, void* userData) {
  char* itemName = (char*)item;
  CharString tempPath = newCharString();
  ErrorReporter errorReporter = (ErrorReporter)userData;
  charStringCopyCString(tempPath, itemName);
  snprintf(tempPath->data, tempPath->length, "%s/%s", errorReporter->reportName->data, itemName);
  strncpy(itemName, tempPath->data, tempPath->length);
}
Пример #23
0
CharString getTestResourcePath(const CharString resourcesPath,
                               const char *resourceType,
                               const char *resourceName) {
  CharString filename = newCharString();
  snprintf(filename->data, filename->capacity, "%s%c%s%c%s",
           resourcesPath->data, PATH_DELIMITER, resourceType, PATH_DELIMITER,
           resourceName);
  return filename;
}
Пример #24
0
void logCritical(const char* message, ...) {
  va_list arguments;
  CharString formattedMessage = newCharString();
  va_start(arguments, message);
  // Instead of going through the common logging method, we always dump critical messages to stderr
  vsnprintf(formattedMessage->data, formattedMessage->capacity, message, arguments);
  fprintf(stderr, "ERROR: %s\n", formattedMessage->data);
  freeCharString(formattedMessage);
}
Пример #25
0
static int _testGetFileDirname(void) {
  CharString filename = newCharStringWithCString(ABSOLUTE_TEST_FILENAME);
  CharString expected = newCharString();
  CharString result = newCharString();

#if UNIX
  charStringCopyCString(expected, "/tmp");
#elif WINDOWS
  charStringCopyCString(expected, "C:\\Temp");
#endif
  getFileDirname(filename, result);
  assertCharStringEquals(result, expected->data);

  freeCharString(filename);
  freeCharString(expected);
  freeCharString(result);
  return 0;
}
Пример #26
0
static CharString _getTestPluginResourcesPath(const CharString resourcesPath) {
  CharString pluginRoot = newCharString();
  PlatformInfo platform = newPlatformInfo();
  snprintf(pluginRoot->data, pluginRoot->capacity, "%s%cvst%c%s",
           resourcesPath->data, PATH_DELIMITER, PATH_DELIMITER,
           _getPlatformVstDirName(platform));
  freePlatformInfo(platform);
  return pluginRoot;
}
Пример #27
0
static CharString _fileUtilitiesMakeTempDir(void) {
  CharString tempDirName = newCharString();
#if UNIX
  snprintf(tempDirName->data, tempDirName->capacity, "/tmp/mrswatsontest-XXXXXX");
  mktemp(tempDirName->data);
#elif WINDOWS
  CharString systemTempDir = newCharString();
  CharString randomDirName = newCharString();
  snprintf(randomDirName->data, randomDirName->capacity, "mrswatsontest-%d", rand());
  GetTempPathA(systemTempDir->capacity, systemTempDir->data);
  buildAbsolutePath(systemTempDir, randomDirName, NULL, tempDirName);
  freeCharString(systemTempDir);
  freeCharString(randomDirName);
#endif
  if(!makeDirectory(tempDirName)) {
    fprintf(stderr, "WARNING: Could not make temporary directory\n");
    return NULL;
  }
  return tempDirName;
}
Пример #28
0
void logInternalError(const char* message, ...) {
  va_list arguments;
  CharString versionString;
  CharString formattedMessage = newCharString();

  va_start(arguments, message);
  // Instead of going through the common logging method, we always dump critical messages to stderr
  vsnprintf(formattedMessage->data, formattedMessage->capacity, message, arguments);
  fprintf(stderr, "INTERNAL ERROR: %s\n", formattedMessage->data);
  freeCharString(formattedMessage);

  fprintf(stderr, "  This should not have happened. Please take a minute to report a bug.\n");
  fprintf(stderr, "  Support website: %s\n", SUPPORT_WEBSITE);
  fprintf(stderr, "  Support email: %s\n", SUPPORT_EMAIL);

  versionString = newCharString();
  fillVersionString(versionString);
  fprintf(stderr, "  Program version: %s, build %ld\n", versionString->data, buildDatestamp());
  freeCharString(versionString);
}
Пример #29
0
boolByte errorReportCopyFileToReport(ErrorReporter self, CharString path) {
  boolByte success = false;
  CharString destination = newCharString();

  charStringCopy(destination, path);
  errorReporterRemapPath(self, destination);
  success = copyFileToDirectory(path, self->reportDirPath);

  freeCharString(destination);
  return success;
}
Пример #30
0
static int _testAppendItemToList(void) {
  LinkedList l = newLinkedList();
  CharString c = newCharString();
  charStringCopyCString(c, TEST_ITEM_STRING);
  linkedListAppend(l, c);
  assertNotNull(l->item);
  assertCharStringEquals(((CharString)l->item), TEST_ITEM_STRING);
  assertIsNull(l->nextItem);
  freeLinkedListAndItems(l, (LinkedListFreeItemFunc)freeCharString);
  return 0;
}