Example #1
0
static Block::UID getBlockUIDFromSerialNumber (const juce::String& serial) noexcept
{
    if (serial.length() < (int) sizeof (BlocksProtocol::BlockSerialNumber))
    {
        jassertfalse;
        return getBlockUIDFromSerialNumber (serial.paddedRight ('0', sizeof (BlocksProtocol::BlockSerialNumber)));
    }

    return getBlockUIDFromSerialNumber ((const uint8*) serial.toRawUTF8());
}
juce::File IRBrowserComponent::checkMatchingTrueStereoFile(const juce::String& fileNameBody,
                                                           const juce::String& fileNameExt,
                                                           const juce::File& directory,
                                                           const juce::String& pattern,
                                                           const juce::String& replacement,
                                                           const size_t sampleCount,
                                                           const double sampleRate) const
{
  std::vector<juce::String> candidateNames;
  if (fileNameBody.startsWith(pattern))
  {
    candidateNames.push_back(replacement + fileNameBody.substring(pattern.length(), fileNameBody.length()) + fileNameExt);
  }
  if (fileNameBody.endsWith(pattern))
  {
    candidateNames.push_back(fileNameBody.substring(0, fileNameBody.length()-pattern.length()) + replacement + fileNameExt);
  }

  for (size_t i=0; i<candidateNames.size(); ++i)
  {
    const juce::String& candidateName = candidateNames[i];
    if (directory.getNumberOfChildFiles(juce::File::findFiles|juce::File::ignoreHiddenFiles, candidateName) == 1)
    {
      const juce::File candidateFile = directory.getChildFile(candidateName);
      size_t candidateChannelCount = 0;
      size_t candidateSampleCount = 0;
      double candidateSampleRate = 0.0;
      const bool fileInfoSuccess = readAudioFileInfo(candidateFile, candidateChannelCount, candidateSampleCount, candidateSampleRate);
      if (fileInfoSuccess &&
          candidateChannelCount == 2 &&
          candidateSampleCount == sampleCount &&
          ::fabs(candidateSampleRate - sampleRate) < 0.000001)
      {
        return candidateFile;
      }
    }
  }

  return juce::File::nonexistent;
}
void LufsPluginEditor::exportToText( bool useCommasForDigitSeparation )
{
    LufsAudioProcessor* processor = getProcessor();

    const int updateSize = processor->m_lufsProcessor.getValidSize();

    const juce::String saveDirString( "saveDirectory" );
    const juce::String saveDir = getProcessor()->m_settings.getUserSettings()->getValue( saveDirString );

    juce::File directory;
    if ( saveDir.length() )
        directory = juce::File( directory );
    if ( !directory.exists() )
        directory = juce::File::getSpecialLocation( juce::File::userHomeDirectory );

    juce::FileChooser fileChooser( "Select text output file", directory, "*.txt" );
    if ( fileChooser.browseForFileToSave( true ) )
    {
        juce::File file( fileChooser.getResult() );
        if ( ! file.deleteFile() )
        {
            juce::AlertWindow::showMessageBox( juce::AlertWindow::NoIcon, "Unable to delete existing file, not saving.", "" );
            return;
        }

        // save chosen directory
        getProcessor()->m_settings.getUserSettings()->getValue( saveDirString, file.getParentDirectory().getFullPathName() );

        juce::FileOutputStream outputStream( file );

        juce::String text = "Time\tMomentary\tShort Term\tIntegrated\n";

        for ( int tens = 0; tens < updateSize ; tens += 10 )
        {
            // add time 
            const int seconds = tens / 10;
            const int hours = seconds / 3600;
            const int minutes = ( seconds - hours * 60 ) / 60;
            int shownSeconds = seconds - hours * 3600 - minutes * 60;
            juce::String line( hours );
            line << ":";
            if ( minutes < 10 )
                line << "0";
            line << minutes;
            line << ":";
            if ( shownSeconds < 10 )
                line << "0";
            line << shownSeconds;
            line << "\t";

            // add momentary
            line << juce::String( processor->m_lufsProcessor.getMomentaryVolumeArray()[ tens ], 1 );
            line << "\t";

            // add short term
            line << juce::String( processor->m_lufsProcessor.getShortTermVolumeArray()[ tens ], 1 );
            line << "\t";

            // add integrated
            line << juce::String( processor->m_lufsProcessor.getIntegratedVolumeArray()[ tens ], 1 );
            line << "\n";

            if ( useCommasForDigitSeparation )
                line = line.replaceCharacter( '.', ',' );

            text << line;
        }

        outputStream.writeText( text, false, false );
    }
}