void IRBrowserComponent::selectionChanged()
{
  if (_infoLabel)
  {
    juce::String infoText;
    
    const juce::File file = _fileTreeComponent ? _fileTreeComponent->getSelectedFile() : juce::File::nonexistent;

    if (!file.isDirectory() && _processor)
    {
      size_t channelCount = 0;
      size_t sampleCount = 0;
      double sampleRate = 0.0;
      if (readAudioFileInfo(file, channelCount, sampleCount, sampleRate))
      {
        infoText += juce::String("Name: ") + file.getFileName();
        infoText += juce::String("\n");
        infoText += juce::String("\nSamples: ") + juce::String(static_cast<int>(sampleCount));
        if (sampleRate > 0.00001)
        {
          const double seconds = static_cast<double>(sampleCount) / sampleRate;
          infoText += juce::String("\nDuration: ") + juce::String(seconds, 2) + juce::String("s");
        }
        infoText += juce::String("\nChannels: ") + juce::String(static_cast<int>(channelCount));
        infoText += juce::String("\nSample Rate: ") + juce::String(static_cast<int>(sampleRate)) + juce::String("Hz");

        if (_processor->getNumInputChannels() >= 2 && _processor->getNumOutputChannels() >= 2)
        {
          const TrueStereoPairs trueStereoPairs = findTrueStereoPairs(file, sampleCount, sampleRate);        
          for (size_t i=0; i<trueStereoPairs.size(); ++i)
          {
            if (trueStereoPairs[i].first != file && trueStereoPairs[i].first != juce::File::nonexistent)
            {
              infoText += juce::String("\n");
              infoText += juce::String("\nFile Pair For True-Stereo:");
              infoText += juce::String("\n - ") + file.getFileName();
              infoText += juce::String("\n - ") + trueStereoPairs[i].first.getFileName();
              break;
            }
          }
        }
      }
      else
      {
        infoText += juce::String("\n\nError!\n\nNo information available.");
      }
    }
    
    _infoLabel->setJustificationType(juce::Justification(juce::Justification::topLeft));
    _infoLabel->setText(infoText, sendNotification);
  }
}
//==============================================================================
void LineEndingsConverter::cleanFile (const juce::File& file, const juce::String& lineEndingToUse)
{
    if (! file.hasWriteAccess())
        return;

    juce::StringArray lines;
    file.readLines (lines);

    juce::ScopedPointer<juce::FileOutputStream> stream (file.createOutputStream());

    if (stream != nullptr)
        writeLinesToStream (stream, lines, lineEndingToUse);
}
/**
    Applies polyphase FIR filter 

    Coefficients create a 24 kHz low pass filter for a 192 kHz wave
*/
void AudioProcessing::TestSimpleConvolution( const juce::File & input )
{
    const int polyphase4Size = sizeof(filterPhase0) / sizeof(float);
    const int convolutionSize = 4 * polyphase4Size;
    juce::AudioSampleBuffer convolutionFilter( 1, convolutionSize );

    float * data = convolutionFilter.getWritePointer( 0 );
    for ( int i = 0 ; i < polyphase4Size ; ++ i )
    {
        *data++ = filterPhase0[ i ];
        *data++ = filterPhase1[ i ];
        *data++ = filterPhase2[ i ];
        *data++ = filterPhase3[ i ];
    }

    juce::AudioFormatManager audioFormatManager;
    audioFormatManager.registerBasicFormats();

    juce::AudioFormatReader * reader = audioFormatManager.createReaderFor( input );

    if ( reader != nullptr )
    {
        // read file
        juce::AudioSampleBuffer origin( (int)reader->numChannels, (int)reader->lengthInSamples );
        reader->read( &origin, 0, (int)reader->lengthInSamples, 0, true, true );

        // Convolve
        juce::AudioSampleBuffer output;
        convolution( origin, convolutionFilter, output );
        output.applyGain(0.25f); // filter values use sample with 3 zeros per valid sample (1 / 4)

        juce::String outputName = input.getFullPathName().substring(0, input.getFullPathName().length() - 4);
        juce::File outputFile( outputName + "_convolution.wav" );
        juce::FileOutputStream * outputStream = new juce::FileOutputStream( outputFile );

        juce::WavAudioFormat wavAudioFormat;

        juce::StringPairArray emptyArray;
        juce::AudioFormatWriter * writer = wavAudioFormat.createWriterFor( 
            outputStream, reader->sampleRate, reader->numChannels, 24, emptyArray, 0 );

        if ( writer != nullptr )
        {
            writer->writeFromAudioSampleBuffer( output, 0, output.getNumSamples() );

            delete writer;
        }

        delete reader;
    }
}
void CodeFileList::addDirectory (const juce::File& file)
{
    if (file.isDirectory())
    {
        juce::Array<juce::File> results;
        file.findChildFiles (results, juce::File::findFiles, true, wildcards);

        for (int i = results.size(); --i >= 0;)
            files.addIfNotAlreadyThere (results.getReference (i).getFullPathName()); //N.B.: Don't use addFile() - it will be a redundant check to see if the file is valid
    }
    else
    {
        addFile (file.getFullPathName());
    }
}
void InterfaceComponent::buttonClicked (juce::Button* button)
{
    if (button == &btnBrowse)
    {
        juce::FileChooser chooser ("Select the folder which contains the code files you want to modularise");
        
        if (chooser.browseForDirectory())
        {
            const juce::File folder (chooser.getResult());

            txtSourceFileFolder.setText (folder.getFullPathName().trim(), juce::sendNotification);
            txtDestinationFolder.setText (folder.getParentDirectory().getFullPathName().trim(), juce::sendNotification);

            files = Modulariser (folder, true).getFiles();

            fileListBox.setSelectedRows (juce::SparseSet<int>());
            fileListBox.updateContent();
        }
    }
    else if (button == &btnRefresh)
    {
        refresh();
    }
    else if (button == &btnGenerate)
    {
        const juce::String srcFolder (txtSourceFileFolder.getText().trim());
        const juce::String destFolder (txtDestinationFolder.getText().trim());

        if (srcFolder.isNotEmpty()
            && destFolder.isNotEmpty()
            && juce::File::isAbsolutePath (srcFolder)
            && juce::File::isAbsolutePath (destFolder))
        {
            Modulariser modulariser (files);

            modulariser.saveTo (juce::File (destFolder),
                                srcFolder,
                                txtModuleFilename.getText().trim(),
                                txtHeaderGuard.getText().trim(),
                                txtNamespace.getText().trim());
        }
    }
}
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 AudioProcessing::TestOversampling( const juce::File & input )
{
    juce::AudioFormatManager audioFormatManager;
    audioFormatManager.registerBasicFormats();

    juce::AudioFormatReader * reader = audioFormatManager.createReaderFor( input );

    if ( reader != nullptr )
    {
        // read file
        juce::AudioSampleBuffer origin( (int)reader->numChannels, (int)reader->lengthInSamples );
        reader->read( &origin, 0, (int)reader->lengthInSamples, 0, true, true );

        // Use polyphase FIR filter with coefficients for upsampling 4 times at 48KHz
        juce::AudioSampleBuffer output;
        polyphase4( origin, output );


        juce::String outputName = input.getFullPathName().substring(0, input.getFullPathName().length() - 4);
        juce::File outputFile( outputName + "_polyphase4.wav" );
        juce::FileOutputStream * outputStream = new juce::FileOutputStream( outputFile );

        juce::WavAudioFormat wavAudioFormat;

        juce::StringPairArray emptyArray;
        juce::AudioFormatWriter * writer = wavAudioFormat.createWriterFor( 
            outputStream, reader->sampleRate, reader->numChannels, 24, emptyArray, 0 );

        if ( writer != nullptr )
        {
            writer->writeFromAudioSampleBuffer( output, 0, output.getNumSamples() );
            
            delete writer;
        }

        delete reader;
    }
}
Example #8
0
//==============================================================================
bool CodeTool::canApplyToFile (const juce::File& file) const
{
    return file.hasFileExtension (CodeFileList::getAllWildcards().removeCharacters ("*"));
}
void CodeFileList::addFile (const juce::File& file)
{
    addFile (file.getFullPathName().trim());
}
IRBrowserComponent::TrueStereoPairs IRBrowserComponent::findTrueStereoPairs(const juce::File& file, size_t sampleCount, double sampleRate) const
{
  if (file == juce::File::nonexistent || file.isDirectory())
  {
    return TrueStereoPairs();
  }

  const juce::File directory = file.getParentDirectory();
  if (file == juce::File::nonexistent || file.isDirectory())
  {
    return TrueStereoPairs();
  }

  const juce::String fileNameBody = file.getFileNameWithoutExtension();
  const juce::String fileNameExt = file.getFileExtension();

  // Left => Right
  static std::vector<std::pair<juce::String, juce::String> > pairsLeft;
  if (pairsLeft.empty())
  {
    pairsLeft.push_back(std::make_pair(juce::String("L"),    juce::String("R")));
    pairsLeft.push_back(std::make_pair(juce::String("l"),    juce::String("r")));
    pairsLeft.push_back(std::make_pair(juce::String("Left"), juce::String("Right")));
    pairsLeft.push_back(std::make_pair(juce::String("left"), juce::String("right")));
    pairsLeft.push_back(std::make_pair(juce::String("LEFT"), juce::String("RIGHT")));
  }
  for (size_t i=0; i<pairsLeft.size(); ++i)
  {
    const juce::File matchingFile = checkMatchingTrueStereoFile(fileNameBody,
                                                                fileNameExt,
                                                                directory,
                                                                pairsLeft[i].first,
                                                                pairsLeft[i].second,
                                                                sampleCount,
                                                                sampleRate);
    if (matchingFile != juce::File::nonexistent)
    {
      TrueStereoPairs trueStereoPairs;
      trueStereoPairs.push_back(std::make_pair(file, 0));
      trueStereoPairs.push_back(std::make_pair(file, 1));
      trueStereoPairs.push_back(std::make_pair(matchingFile, 0));
      trueStereoPairs.push_back(std::make_pair(matchingFile, 1));
      return trueStereoPairs;
    }
  }

  static std::vector<std::pair<juce::String, juce::String> > pairsRight;
  if (pairsRight.empty())
  {
    pairsRight.push_back(std::make_pair(juce::String("R"),     juce::String("L")));
    pairsRight.push_back(std::make_pair(juce::String("r"),     juce::String("l")));
    pairsRight.push_back(std::make_pair(juce::String("Right"), juce::String("Left")));
    pairsRight.push_back(std::make_pair(juce::String("right"), juce::String("left")));
    pairsRight.push_back(std::make_pair(juce::String("RIGHT"), juce::String("LEFT")));
  }
  for (size_t i=0; i<pairsRight.size(); ++i)
  {
    const juce::File matchingFile = checkMatchingTrueStereoFile(fileNameBody,
                                                                fileNameExt,
                                                                directory,
                                                                pairsRight[i].first,
                                                                pairsRight[i].second,
                                                                sampleCount,
                                                                sampleRate);
    if (matchingFile != juce::File::nonexistent)
    {
      TrueStereoPairs trueStereoPairs;
      trueStereoPairs.push_back(std::make_pair(matchingFile, 0));
      trueStereoPairs.push_back(std::make_pair(matchingFile, 1));
      trueStereoPairs.push_back(std::make_pair(file, 0));
      trueStereoPairs.push_back(std::make_pair(file, 1));
      return trueStereoPairs;
    }
  }

  return TrueStereoPairs();
}
//==============================================================================
void TrailingWhitespaceCleaner::cleanFile (const juce::File& file,
                                           const bool removeDocumentStartWhitespace,
                                           const WhitespaceRemovalOptions documentEndOptions)
{
    if (! file.hasWriteAccess())
        return;

    juce::StringArray lines;
    file.readLines (lines);

    if (lines.size() <= 0)
        return;

    while (lines.strings.getLast().trim().isEmpty())
        lines.remove (lines.size() - 1);

    lines.minimiseStorageOverheads();

    cleanRange (lines, 0, lines.size());

    if (removeDocumentStartWhitespace)
    {
        for (int i = 0; i < lines.size(); ++i)
        {
            if (lines[i].isEmpty())
            {
                lines.remove (i);
                --i;
            }
            else
            {
                break;
            }
        }
    }

    //Remove empty lines at the end of the file:
    for (int i = lines.size(); --i >= 0;)
    {
        if (lines[i].isEmpty())
            lines.remove (i);
        else
            break;
    }
#if 0
    if (documentEndOptions == KeepOneBlankLine)
    {
        const juce::String last (lines.strings[lines.size() - 1].trim());

        if (lines.size() == 0)
        {
            lines.add (juce::newLine);
        }
        else
        {
            if (last.isNotEmpty())
            {
                if (last == "\r" || last == "\n" || last == "\n\r" || last == "\r\n")
                    lines.strings.getReference (lines.size() - 1) = juce::newLine;
                else
                    lines.add (juce::newLine);
            }
            else
            {
                lines.strings.getReference (lines.size() - 1) = juce::newLine;
            }
        }
    }
#endif
    juce::ScopedPointer<juce::FileOutputStream> stream (file.createOutputStream());

    if (stream != nullptr)
        writeLinesToStream (stream, lines);
}