Exemplo n.º 1
0
void CtrlrMidiBufferStatus::update(const int x, const int y)
{
	size.setText(STR(owner.getDataSize()/3));

	status.setFont (statusFont);
	status.setText ("Byte: ");
	CodeDocument::Position pos = owner.getCodeEditor().getPositionAt (x,y);

	status.append (STR(pos.getPosition()/3), statusFont.boldened());
	status.append ("/"+STR(pos.getPosition()), statusFont);
	status.append (" "+currentByte(pos), statusFont);

	Range<int> sel = owner.getCodeEditor().getHighlightedRegion();
	if (!sel.isEmpty())
	{
		const int end   = sel.getEnd() / 3;
		const int start = sel.getStart() / 3;
		String selection = owner.getCodeEditor().getTextInRange (Range<int> (sel.getStart(),sel.getEnd())).trim();

		status.append (" Selected("+STR((end - start)+1)+"): ", statusFont);
		status.append (STR(start), statusFont.boldened());
		status.append (" - ", statusFont);
		status.append (STR(end), statusFont.boldened());
		status.append (" "+hexString(selection), statusFont);
	}

	repaint();
}
Exemplo n.º 2
0
float ModulatorSamplerSound::getGainValueForVelocityXFade(int velocity)
{
	if (upperVeloXFadeValue == 0 && lowerVeloXFadeValue == 0) return 1.0f;

	Range<int> upperRange = Range<int>(velocityRange.getHighestBit() - upperVeloXFadeValue, velocityRange.getHighestBit());
	Range<int> lowerRange = Range<int>(velocityRange.findNextSetBit(0), velocityRange.findNextSetBit(0) + lowerVeloXFadeValue);

	float delta = 1.0f;

	if (upperRange.contains(velocity))
	{
		delta = (float)(velocity - upperRange.getStart()) / (upperRange.getLength());

		return Interpolator::interpolateLinear(1.0f, 0.0f, delta);
	}
	else if (lowerRange.contains(velocity))
	{
		delta = (float)(velocity - lowerRange.getStart()) / (lowerRange.getLength());

		return Interpolator::interpolateLinear(0.0f, 1.0f, delta);
	}
	else
	{
		return 1.0f;
	}
}
void CodeEditorComponent::scrollToKeepLinesOnScreen (Range<int> rangeToShow)
{
    if (rangeToShow.getStart() < firstLineOnScreen)
        scrollBy (rangeToShow.getStart() - firstLineOnScreen);
    else if (rangeToShow.getEnd() >= firstLineOnScreen + linesOnScreen)
        scrollBy (rangeToShow.getEnd() - (firstLineOnScreen + linesOnScreen - 1));
}
CodeEditorComponent::State::State (const CodeEditorComponent& editor)
    : lastTopLine (editor.getFirstLineOnScreen()),
      lastCaretPos (editor.getCaretPos().getPosition()),
      lastSelectionEnd (lastCaretPos)
{
    const Range<int> selection (editor.getHighlightedRegion());

    if (lastCaretPos == selection.getStart())
        lastSelectionEnd = selection.getEnd();
    else
        lastSelectionEnd = selection.getStart();
}
Exemplo n.º 5
0
string Effect::Summon::getDescription() const {
  Range number = getSummonNumber(creature);
  if (number.getEnd() > 2)
    return "Summons " + toString(number.getStart()) + " to " + toString(number.getEnd() - 1)
        + getCreatureName(creature);
  else
    return "Summons " + getCreatureAName(creature);
}
void CtrlrLuaMethodCodeEditor::reportFoundMatch (CodeDocument &document, const String &methodName, const Range<int> range)
{
	CodeDocument::Position pos (document, range.getStart());
	AttributedString as;
	as.append ("Method: ", Colours::black);
	as.append (methodName, Colours::blue);

	as.append ("\tline: ", Colours::black);
	as.append (String(pos.getLineNumber()+1), Colours::darkgreen);

	as.append ("\tstart: ", Colours::black);
	as.append (String(range.getStart()), Colours::darkgreen);

	as.append ("\tend: ", Colours::black);
	as.append (String(range.getEnd()), Colours::darkgreen);

	owner.getMethodEditArea()->insertOutput (as);
}
static void getStereoMinAndMax (SampleType* const* channels, const int numChannels, const int numSamples,
                                SampleType& lmin, SampleType& lmax, SampleType& rmin, SampleType& rmax)
{
    Range<SampleType> range (getChannelMinAndMax (channels[0], numSamples));
    lmax = jmax (lmax, range.getEnd());
    lmin = jmin (lmin, range.getStart());

    if (numChannels > 1)
    {
        range = getChannelMinAndMax (channels[1], numSamples);
        rmax = jmax (rmax, range.getEnd());
        rmin = jmin (rmin, range.getStart());
    }
    else
    {
        rmax = lmax;
        rmin = lmin;
    }
}
Exemplo n.º 8
0
void SimpleTypeLayout::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));
}
Exemplo n.º 9
0
void
TimelineComponent::updateClip (TimelineClip* clip)
{
    jassert (clip);

    ClipRange<double> time;
    clip->getClipRange (time);

    const Range<int> hrange (trackHeight (clip->trackIndex()));
    clip->setBounds (timeToX (time.getStart(), clip->getTimeUnit()), hrange.getStart(),
                     timeToWidth (time, clip->getTimeUnit()), hrange.getLength());
}
Exemplo n.º 10
0
    inline void setFloat (Range<float> newRange) noexcept
    {
        values[0] = (int8) jlimit (-128, 127, roundFloatToInt (newRange.getStart() * 127.0f));
        values[1] = (int8) jlimit (-128, 127, roundFloatToInt (newRange.getEnd()   * 127.0f));

        if (values[0] == values[1])
        {
            if (values[1] == 127)
                values[0]--;
            else
                values[1]++;
        }
    }
Exemplo n.º 11
0
void AudioFormatReader::readMaxLevels (int64 startSampleInFile, int64 numSamples,
                                       Range<float>* const results, const int channelsToRead)
{
    jassert (channelsToRead > 0 && channelsToRead <= numChannels);

    if (numSamples <= 0)
    {
        for (int i = 0; i < channelsToRead; ++i)
            results[i] = Range<float>();

        return;
    }

    const int bufferSize = (int) jmin (numSamples, (int64) 4096);
    AudioSampleBuffer tempSampleBuffer ((int) channelsToRead, bufferSize);

    float* const* const floatBuffer = tempSampleBuffer.getArrayOfWritePointers();
    int* const* intBuffer = reinterpret_cast<int* const*> (floatBuffer);
    bool isFirstBlock = true;

    while (numSamples > 0)
    {
        const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
        if (! read (intBuffer, channelsToRead, startSampleInFile, numToDo, false))
            break;

        for (int i = 0; i < channelsToRead; ++i)
        {
            Range<float> r;

            if (usesFloatingPointData)
            {
                r = FloatVectorOperations::findMinAndMax (floatBuffer[i], numToDo);
            }
            else
            {
                Range<int> intRange (Range<int>::findMinAndMax (intBuffer[i], numToDo));

                r = Range<float> (intRange.getStart() / (float) std::numeric_limits<int>::max(),
                                  intRange.getEnd()   / (float) std::numeric_limits<int>::max());
            }

            results[i] = isFirstBlock ? r : results[i].getUnionWith (r);
        }

        isFirstBlock = false;
        numSamples -= numToDo;
        startSampleInFile += numToDo;
    }
}
Exemplo n.º 12
0
void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
{
    if (hasAlphaChannel())
    {
        const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
        SparseSet<int> pixelsOnRow;

        const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());

        for (int y = 0; y < srcData.height; ++y)
        {
            pixelsOnRow.clear();
            const uint8* lineData = srcData.getLinePointer (y);

            if (isARGB())
            {
                for (int x = 0; x < srcData.width; ++x)
                {
                    if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
                        pixelsOnRow.addRange (Range<int> (x, x + 1));

                    lineData += srcData.pixelStride;
                }
            }
            else
            {
                for (int x = 0; x < srcData.width; ++x)
                {
                    if (*lineData >= threshold)
                        pixelsOnRow.addRange (Range<int> (x, x + 1));

                    lineData += srcData.pixelStride;
                }
            }

            for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
            {
                const Range<int> range (pixelsOnRow.getRange (i));
                result.add (Rectangle<int> (range.getStart(), y, range.getLength(), 1));
            }

            result.consolidate();
        }
    }
    else
    {
        result.add (0, 0, getWidth(), getHeight());
    }
}
File UnityProjectBuilder::buildUnityCpp (const File& destDir, int unityNum, const Range<int> fileRange)
{
    const File cppFile (destDir.getChildFile (unityName + String (unityNum)).withFileExtension (".cpp"));
    logOutput ("Building Unity cpp file \"" + cppFile.getFullPathName() + "\"...");
    
    if (cppFile.existsAsFile())
        cppFile.deleteFile();
    
    FileOutputStream s (cppFile);
    
    for (int i = fileRange.getStart(); i < fileRange.getEnd(); ++i)
        s << "#include \"" << filesToAdd[i] << "\"" << newLine;
    
    return cppFile;
}
Exemplo n.º 14
0
void TextLayout::recalculateWidth()
{
    if (lines.size() > 0)
    {
        Range<float> range (lines.getFirst()->getLineBoundsX());

        int i;
        for (i = lines.size(); --i > 0;)
            range = range.getUnionWith (lines.getUnchecked(i)->getLineBoundsX());

        for (i = lines.size(); --i >= 0;)
            lines.getUnchecked(i)->lineOrigin.x -= range.getStart();

        width = range.getLength();
    }
}
Exemplo n.º 15
0
bool MemoryMappedAudioFormatReader::mapSectionOfFile (Range<int64> samplesToMap)
{
    if (map == nullptr || samplesToMap != mappedSection)
    {
        map = nullptr;

        const Range<int64> fileRange (sampleToFilePos (samplesToMap.getStart()),
                                      sampleToFilePos (samplesToMap.getEnd()));

        map = new MemoryMappedFile (file, fileRange, MemoryMappedFile::readOnly);

        if (map->getData() == nullptr)
            map = nullptr;
        else
            mappedSection = Range<int64> (jmax ((int64) 0, filePosToSample (map->getRange().getStart() + (bytesPerFrame - 1))),
                                          jmin (lengthInSamples, filePosToSample (map->getRange().getEnd())));
    }

    return map != nullptr;
}
Exemplo n.º 16
0
 double xToTime (const float x) const
 {
     return (x / getWidth()) * (visibleRange.getLength()) + visibleRange.getStart();
 }
Exemplo n.º 17
0
 float timeToX (const double time) const
 {
     return getWidth() * (float) ((time - visibleRange.getStart()) / (visibleRange.getLength()));
 }
Exemplo n.º 18
0
int RandomGen::get(Range r) {
  return get(r.getStart(), r.getEnd());
}
Exemplo n.º 19
0
int TimelineComponent::timeToWidth (const Range<double>& time, const TimeUnit unit) const
{
    return timeToX (time.getEnd(), unit) - timeToX (time.getStart(), unit);
}
Exemplo n.º 20
0
    void runTest() override
    {
        beginTest ("initialisation");
        {
            {
                MPEZone zone (1, 10);

                expectEquals (zone.getMasterChannel(), 1);
                expectEquals (zone.getNumNoteChannels(), 10);
                expectEquals (zone.getFirstNoteChannel(), 2);
                expectEquals (zone.getLastNoteChannel(), 11);
                expectEquals (zone.getPerNotePitchbendRange(), 48);
                expectEquals (zone.getMasterPitchbendRange(), 2);

                expect (zone.isUsingChannel (1));
                expect (zone.isUsingChannel (2));
                expect (zone.isUsingChannel (10));
                expect (zone.isUsingChannel (11));
                expect (! zone.isUsingChannel (12));
                expect (! zone.isUsingChannel (16));

                expect (! zone.isUsingChannelAsNoteChannel (1));
                expect (zone.isUsingChannelAsNoteChannel (2));
                expect (zone.isUsingChannelAsNoteChannel (10));
                expect (zone.isUsingChannelAsNoteChannel (11));
                expect (! zone.isUsingChannelAsNoteChannel (12));
                expect (! zone.isUsingChannelAsNoteChannel (16));
            }
            {
                MPEZone zone (5, 4);

                expectEquals (zone.getMasterChannel(), 5);
                expectEquals (zone.getNumNoteChannels(), 4);
                expectEquals (zone.getFirstNoteChannel(), 6);
                expectEquals (zone.getLastNoteChannel(), 9);
                expectEquals (zone.getPerNotePitchbendRange(), 48);
                expectEquals (zone.getMasterPitchbendRange(), 2);

                expect (! zone.isUsingChannel (1));
                expect (! zone.isUsingChannel (4));
                expect (zone.isUsingChannel (5));
                expect (zone.isUsingChannel (6));
                expect (zone.isUsingChannel (8));
                expect (zone.isUsingChannel (9));
                expect (! zone.isUsingChannel (10));
                expect (! zone.isUsingChannel (16));

                expect (! zone.isUsingChannelAsNoteChannel (5));
                expect (zone.isUsingChannelAsNoteChannel (6));
                expect (zone.isUsingChannelAsNoteChannel (8));
                expect (zone.isUsingChannelAsNoteChannel (9));
                expect (! zone.isUsingChannelAsNoteChannel (10));
            }

        }

        beginTest ("getNoteChannelRange");
        {
            MPEZone zone (2, 10);

            Range<int> noteChannelRange = zone.getNoteChannelRange();
            expectEquals (noteChannelRange.getStart(), 3);
            expectEquals (noteChannelRange.getEnd(), 13);
        }

        beginTest ("setting master pitchbend range");
        {
            MPEZone zone (1, 10);

            zone.setMasterPitchbendRange (96);
            expectEquals (zone.getMasterPitchbendRange(), 96);
            zone.setMasterPitchbendRange (0);
            expectEquals (zone.getMasterPitchbendRange(), 0);

            expectEquals (zone.getPerNotePitchbendRange(), 48);
        }

        beginTest ("setting per-note pitchbend range");
        {
            MPEZone zone (1, 10);

            zone.setPerNotePitchbendRange (96);
            expectEquals (zone.getPerNotePitchbendRange(), 96);
            zone.setPerNotePitchbendRange (0);
            expectEquals (zone.getPerNotePitchbendRange(), 0);

            expectEquals (zone.getMasterPitchbendRange(), 2);
        }

        beginTest ("checking overlap");
        {
            testOverlapsWith (1, 10, 1, 10, true);
            testOverlapsWith (1, 4,  6, 3,  false);
            testOverlapsWith (1, 4,  8, 3,  false);
            testOverlapsWith (2, 10, 2, 8,  true);
            testOverlapsWith (1, 10, 3, 2,  true);
            testOverlapsWith (3, 10, 5, 9,  true);
        }

        beginTest ("truncating");
        {
            testTruncateToFit (1, 10, 3, 10, true,  1, 1);
            testTruncateToFit (3, 10, 1, 10, false, 3, 10);
            testTruncateToFit (1, 10, 5, 8,  true,  1, 3);
            testTruncateToFit (5, 8,  1, 10, false, 5, 8);
            testTruncateToFit (1, 10, 4, 3,  true,  1, 2);
            testTruncateToFit (4, 3,  1, 10, false, 4, 3);
            testTruncateToFit (1, 3,  5, 3,  true,  1, 3);
            testTruncateToFit (5, 3,  1, 3,  false, 5, 3);
            testTruncateToFit (1, 3,  7, 3,  true,  1, 3);
            testTruncateToFit (7, 3,  1, 3,  false, 7, 3);
            testTruncateToFit (1, 10, 2, 10, false, 1, 10);
            testTruncateToFit (2, 10, 1, 10, false, 2, 10);
        }
    }
void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
{
    selectRegion (CodeDocument::Position (document, newRange.getStart()),
                  CodeDocument::Position (document, newRange.getEnd()));
}
const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
{
    return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
                                    CodeDocument::Position (&document, range.getEnd()));
}
void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
{
    moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
    moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
}