void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
 {
     if (thumbnail.getTotalLength() > 0)
     {
         double newStart = startTime + (wheelIncrementX + wheelIncrementY) * (endTime - startTime) / 10.0;
         newStart = jlimit (0.0, thumbnail.getTotalLength() - (endTime - startTime), newStart);
         endTime = newStart + (endTime - startTime);
         startTime = newStart;
         repaint();
     }
 }
void GuitarNeckComponent::setLowestVisibleFret (int fretNumber)
{
    fretNumber = jlimit (rangeStart, rangeEnd, fretNumber);

    if (fretNumber != firstFret)
    {
        firstFret = fretNumber;
        sendChangeMessage();
        resized();
    }
}
示例#3
0
 void setZoomFactor (double amount)
 {
     if (thumbnail.getTotalLength() > 0)
     {
         const double newScale = jmax (0.001, thumbnail.getTotalLength() * (1.0 - jlimit (0.0, 0.99, amount)));
         const double timeAtCentre = xToTime (getWidth() / 2.0f);
         startTime = timeAtCentre - newScale * 0.5;
         endTime = timeAtCentre + newScale * 0.5;
         repaint();
     }
 }
void CodeEditorComponent::scrollToColumnInternal (double column)
{
    const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);

    if (xOffset != newOffset)
    {
        xOffset = newOffset;
        updateCaretPosition();
        repaint();
    }
}
void ColourSelector::setHue (float newH)
{
    newH = jlimit (0.0f, 1.0f, newH);

    if (h != newH)
    {
        h = newH;
        colour = Colour (h, s, v, colour.getFloatAlpha());
        update();
    }
}
bool BufferingAudioSource::waitForNextAudioBlockReady (const AudioSourceChannelInfo& info, const uint32 timeout)
{
    if (!source || source->getTotalLength() <= 0)
        return false;

    if (nextPlayPos + info.numSamples < 0)
        return true;

    if (! isLooping() && nextPlayPos > getTotalLength())
        return true;

    uint32 now = Time::getMillisecondCounter();
    const uint32 startTime = now;

    uint32 elapsed = (now >= startTime ? now - startTime
                                       : (std::numeric_limits<uint32>::max() - startTime) + now);

    while (elapsed <= timeout)
    {
        {
            const ScopedLock sl (bufferStartPosLock);

            const int validStart = static_cast<int> (jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos);
            const int validEnd   = static_cast<int> (jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos);

            if (validStart <= 0 && validStart < validEnd && validEnd >= info.numSamples)
                return true;
        }



        if (elapsed < timeout  && (! bufferReadyEvent.wait (static_cast<int> (timeout - elapsed))))
            return false;

        now = Time::getMillisecondCounter();
        elapsed = (now >= startTime ? now - startTime
                                    : (std::numeric_limits<uint32>::max() - startTime) + now);
    }

    return false;
}
bool MemoryOutputStream::setPosition (int64 newPosition)
{
    if (newPosition <= (int64) size)
    {
        // ok to seek backwards
        position = jlimit ((size_t) 0, size, (size_t) newPosition);
        return true;
    }

    // can't move beyond the end of the stream..
    return false;
}
示例#8
0
double SynthChannel::getWaveformFromPhase(void)
{
	double pulse = phase > jlimit(.1, .9, scale(waveform * 2.0, .5, .95)) ? 1.0 : -1.0;

	if (waveform <= .5) {
		return pulse;
	}
	else {
		double randomValue = phase > scale(random.nextDouble(), .1, .9) ? 1.0 : -1.0;
		return ((1.0 - waveform) * pulse) + (randomValue * pulse); 
	}
}
示例#9
0
void PitchDiracLE::processBlock(float* chL, float* chR, int numSamples)
{
	for (int i=0; i<numSamples; ++i)
	{
		chL[i] *= scale;
		chR[i] *= scale;
	}

	DiracFxProcessFloat(1., pitch, &chL, &chL, numSamples, pitchL);
	DiracFxProcessFloat(1., pitch, &chR, &chR, numSamples, pitchR);

	const float invScale = scale > 0.f ? 1.f / scale : 0.f;

	for (int i=0; i<numSamples; ++i)
	{
		chL[i] *= invScale;
		chR[i] *= invScale;
		chL[i] = jlimit(-1.f, 1.f, chL[i]);
		chR[i] = jlimit(-1.f, 1.f, chR[i]);
	}
}
int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const
{
    JUCE_COLOURGRADIENT_CHECK_COORDS_INITIALISED // Trying to use this object without setting its coordinates?
    jassert (colours.size() >= 2);

    const int numEntries = jlimit (1, jmax (1, (colours.size() - 1) << 8),
                                   3 * (int) point1.transformedBy (transform)
                                                .getDistanceFrom (point2.transformedBy (transform)));
    lookupTable.malloc ((size_t) numEntries);
    createLookupTable (lookupTable, numEntries);
    return numEntries;
}
 void fitToContent (const int h) noexcept
 {
     if (keyNum < 0)
     {
         setSize (h, h);
     }
     else
     {
         Font f (h * 0.6f);
         setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
     }
 }
void PaintRoutineEditor::filesDropped (const StringArray& filenames, int x, int y)
{
    const File f (filenames [0]);

    if (f.existsAsFile())
    {
        ScopedPointer<Drawable> d (Drawable::createFromImageFile (f));

        if (d != nullptr)
        {
            d = nullptr;

            document.beginTransaction();

            graphics.dropImageAt (f,
                                  jlimit (10, getWidth() - 10, x),
                                  jlimit (10, getHeight() - 10, y));

            document.beginTransaction();
        }
    }
}
void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
                                                      const int numSamples)
{
   #if JUCE_DEBUG
    jassert (hasCalledReset); // you need to call reset() to set the correct sample rate before using this object
   #endif

    jassert (numSamples > 0);

    auto timeNow = Time::getMillisecondCounterHiRes();
    auto msElapsed = timeNow - lastCallbackTime;

    const ScopedLock sl (midiCallbackLock);
    lastCallbackTime = timeNow;

    if (! incomingMessages.isEmpty())
    {
        int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
        int startSample = 0;
        int scale = 1 << 16;

        const uint8* midiData;
        int numBytes, samplePosition;

        MidiBuffer::Iterator iter (incomingMessages);

        if (numSourceSamples > numSamples)
        {
            // if our list of events is longer than the buffer we're being
            // asked for, scale them down to squeeze them all in..
            const int maxBlockLengthToUse = numSamples << 5;

            if (numSourceSamples > maxBlockLengthToUse)
            {
                startSample = numSourceSamples - maxBlockLengthToUse;
                numSourceSamples = maxBlockLengthToUse;
                iter.setNextSamplePosition (startSample);
            }

            scale = (numSamples << 10) / numSourceSamples;

            while (iter.getNextEvent (midiData, numBytes, samplePosition))
            {
                samplePosition = ((samplePosition - startSample) * scale) >> 10;

                destBuffer.addEvent (midiData, numBytes,
                                     jlimit (0, numSamples - 1, samplePosition));
            }
        }
        else
        {
BEGIN_JUCE_NAMESPACE

#include "juce_ProgressBar.h"
#include "../lookandfeel/juce_LookAndFeel.h"


//==============================================================================
ProgressBar::ProgressBar (double& progress_)
   : progress (progress_),
     displayPercentage (true),
     lastCallbackTime (0)
{
    currentValue = jlimit (0.0, 1.0, progress);
}
void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
{
    newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
                                   newFirstLineOnScreen);

    if (newFirstLineOnScreen != firstLineOnScreen)
    {
        firstLineOnScreen = newFirstLineOnScreen;
        ((CaretComponent*) caret)->updatePosition (*this);

        updateCachedIterators (firstLineOnScreen);
        triggerAsyncUpdate();
    }
}
示例#16
0
void TabbedButtonBar::removeTab (const int tabIndex)
{
    if (tabs [tabIndex] != nullptr)
    {
        const int oldTabIndex = currentTabIndex;
        if (currentTabIndex == tabIndex)
            currentTabIndex = -1;

        tabs.remove (tabIndex);
        resized();

        setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
    }
}
bool MemoryOutputStream::setPosition (int64 newPosition)
{
    if (newPosition <= (int64) size)
    {
        // ok to seek backwards
        position = jlimit ((size_t) 0, size, (size_t) newPosition);
        return true;
    }
    else
    {
        // trying to make it bigger isn't a good thing to do..
        return false;
    }
}
示例#18
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());
    }
}
示例#19
0
void DRowAudioFilter::refillBuffer()
{
	float bufferIncriment = 1.0f / (float)distortionBufferSize;
	float x = 0.0f;
	for (int i = 0; i < distortionBufferSize; i++)
	{
		x += bufferIncriment;
		x = jlimit(0.0f, 1.0f, x);
		distortionBuffer[i] = BezierCurve::cubicBezierNearlyThroughTwoPoints(x,
																			 params[X1].getValue(),
																			 params[Y1].getValue(),
																			 params[X2].getValue(),
																			 params[Y2].getValue());
	}
}
示例#20
0
    void mouseWheelMove (const MouseEvent&, const MouseWheelDetails& wheel)
    {
        if (thumbnail.getTotalLength() > 0)
        {
            double newStart = startTime - wheel.deltaX * (endTime - startTime) / 10.0;
            newStart = jlimit (0.0, jmax (0.0, thumbnail.getTotalLength() - (endTime - startTime)), newStart);
            endTime = newStart + (endTime - startTime);
            startTime = newStart;

            if (wheel.deltaY != 0)
                zoomSlider.setValue (zoomSlider.getValue() - wheel.deltaY);

            repaint();
        }
    }
void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
{
    newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
                                   newFirstLineOnScreen);

    if (newFirstLineOnScreen != firstLineOnScreen)
    {
        firstLineOnScreen = newFirstLineOnScreen;
        updateCaretPosition();

        updateCachedIterators (firstLineOnScreen);
        rebuildLineTokensAsync();
        pimpl->handleUpdateNowIfNeeded();
    }
}
void MidiKeyboardComponent::setLowestVisibleKeyFloat (float noteNumber)
{
    noteNumber = jlimit ((float) rangeStart, (float) rangeEnd, noteNumber);

    if (noteNumber != firstKey)
    {
        bool hasMoved = (((int) firstKey) != (int) noteNumber);
        firstKey = noteNumber;

        if (hasMoved)
            sendChangeMessage();

        resized();
    }
}
示例#23
0
void FilterGraph::mouseWheelMove (const MouseEvent &event, const MouseWheelDetails &wheel)
{
    int idx = 0;
    
    for (int i=1; i<5; i++)
    {
        if (btn_drag.getUnchecked(i)->getState() == 1)
            idx = i;
        
    }
    
    switch (idx) {
        case 0:
            break;
            
        case 1:
            myprocessor_->setParameter(LowhighpassAudioProcessor::LSQParam, (float)jlimit(0.f, 1.f, myprocessor_->getParameter(LowhighpassAudioProcessor::LSQParam)+wheel.deltaY*0.7f));
            break;
            
        case 2:
            myprocessor_->setParameter(LowhighpassAudioProcessor::PF1QParam, (float)jlimit(0.f, 1.f, myprocessor_->getParameter(LowhighpassAudioProcessor::PF1QParam)+wheel.deltaY*0.7f));
            break;
            
        case 3:
            myprocessor_->setParameter(LowhighpassAudioProcessor::PF2QParam, (float)jlimit(0.f, 1.f, myprocessor_->getParameter(LowhighpassAudioProcessor::PF2QParam)+wheel.deltaY*0.7f));
            break;
            
        case 4:
            myprocessor_->setParameter(LowhighpassAudioProcessor::HSQParam, (float)jlimit(0.f, 1.f, myprocessor_->getParameter(LowhighpassAudioProcessor::HSQParam)+wheel.deltaY*0.7f));
            break;
            
        default:
            break;
    }
    
}
示例#24
0
int ColourGradient::addColour (const double proportionAlongGradient, const Colour& colour)
{
    // must be within the two end-points
    jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);

    const double pos = jlimit (0.0, 1.0, proportionAlongGradient);

    int i;
    for (i = 0; i < colours.size(); ++i)
        if (colours.getReference(i).position > pos)
            break;

    colours.insert (i, ColourPoint (pos, colour));
    return i;
}
示例#25
0
//==============================================================================
int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const
{
   #if JUCE_DEBUG
    // trying to use the object without setting its co-ordinates? Have a careful read of
    // the comments for the constructors.
    jassert (point1.getX() != 987654.0f);
   #endif

    const int numEntries = jlimit (1, jmax (1, (colours.size() - 1) << 8),
                                   3 * (int) point1.transformedBy (transform)
                                                .getDistanceFrom (point2.transformedBy (transform)));
    lookupTable.malloc ((size_t) numEntries);

    if (colours.size() >= 2)
    {
        jassert (colours.getReference(0).position == 0); // the first colour specified has to go at position 0

        PixelARGB pix1 (colours.getReference (0).colour.getPixelARGB());
        int index = 0;

        for (int j = 1; j < colours.size(); ++j)
        {
            const ColourPoint& p = colours.getReference (j);
            const int numToDo = roundToInt (p.position * (numEntries - 1)) - index;
            const PixelARGB pix2 (p.colour.getPixelARGB());

            for (int i = 0; i < numToDo; ++i)
            {
                jassert (index >= 0 && index < numEntries);

                lookupTable[index] = pix1;
                lookupTable[index].tween (pix2, (uint32) (i << 8) / numToDo);
                ++index;
            }

            pix1 = pix2;
        }

        while (index < numEntries)
            lookupTable [index++] = pix1;
    }
    else
    {
        jassertfalse; // no colours specified!
    }

    return numEntries;
}
示例#26
0
    void mouseWheelMove (const MouseEvent&, const MouseWheelDetails& wheel) override
    {
        if (thumbnail.getTotalLength() > 0.0)
        {
            double newStart = visibleRange.getStart() - wheel.deltaX * (visibleRange.getLength()) / 10.0;
            newStart = jlimit (0.0, jmax (0.0, thumbnail.getTotalLength() - (visibleRange.getLength())), newStart);

            if (canMoveTransport())
                setRange (Range<double> (newStart, newStart + visibleRange.getLength()));

            if (wheel.deltaY != 0.0f)
                zoomSlider.setValue (zoomSlider.getValue() - wheel.deltaY);

            repaint();
        }
    }
double EnvelopeHandleComponent::constrainDomain(double domainToConstrain) const
{ 
	EnvelopeHandleComponent* previousHandle = getPreviousHandle();
	EnvelopeHandleComponent* nextHandle = getNextHandle();

	int leftLimit = previousHandle == 0 ? 0 : previousHandle->getX();
	int rightLimit = nextHandle == 0 ? getParentWidth()-HANDLESIZE : nextHandle->getX();
	
	double left = getParentComponent()->convertPixelsToDomain(leftLimit);
	double right = getParentComponent()->convertPixelsToDomain(rightLimit);
	
	if(previousHandle != 0) left += FINETUNE;
	if(nextHandle != 0) right -= FINETUNE;
		
	return jlimit(left, right, shouldLockTime ? time : domainToConstrain);
}
示例#28
0
void DistortionComponent::refillBuffer (float x1, float y1, float x2, float y2)
{
    float* bufferData = buffer.getData();
    const int bufferSize = buffer.getSize();
	const float bufferScale = 1.0f / (float) bufferSize;

	for (int i = 0; i < bufferSize; ++i)
	{
		float x = jlimit (0.0f, 1.0f, i * bufferScale);
		bufferData[i] = BezierCurve::cubicBezierNearlyThroughTwoPoints (x,
                                                                        x1, y1,
                                                                        x2, y2);
	}
    
    buffer.updateListeners();
}
void TerrainHeightHandler::AdjustWorldHeight(int height)
{
	CVertexHeightOperation2* pHeightOperation=new CVertexHeightOperation2;
	pHeightOperation->m_bWorld = true;

	WorldEditorRenderInterface* pInterface=WorldEditorRenderInterface::GetInstance();
	int chunkCount=pInterface->GetChunkSize();
	int cellCount=chunkCount*SGPTT_TILENUM;
	pHeightOperation->ReserveMemory((cellCount+1)*(cellCount+1));

	BOOL bWorldHeight=TRUE;

	for(int i=0;i<=cellCount;++i)
	{
		for(int j=0;j<=cellCount;++j)
		{
			TerrainHeightOpData opData;
			opData.index_x=i;
			opData.index_z=j;
			opData.prevHeight=pInterface->GetTerrainHeight(i,j);
			int currHeight=opData.prevHeight+height;
			opData.currHeight=jlimit(0,65535,currHeight);
			if(opData.currHeight-opData.prevHeight!=height) bWorldHeight=FALSE;
			if(opData.prevHeight!=opData.currHeight) pHeightOperation->AddData(opData);
		}
	}

	if(bWorldHeight)
	{
		CWorldHeightOperation* pWorldOperation=new CWorldHeightOperation;
		pWorldOperation->SetDeltaHeight(height);
		pWorldOperation->redo();
		OperationManager::GetInstance()->AddNewOperation(pWorldOperation);
		
		delete pHeightOperation;
	}
	else
	{
		if(pHeightOperation->HaveData())
		{
			pHeightOperation->redo();
			OperationManager::GetInstance()->AddNewOperation(pHeightOperation);
		}
		else
			delete pHeightOperation;
	}
}
void TerrainHeightHandler::AdjustVertexHeight(int deltaY)
{
	if(!m_bValidate) return ;

	std::vector<TerrainHeightOpData>& DataVector=m_pVertexHeightOp2->m_DataVector;
	int size=DataVector.size();
	float intensityRatio=(0.2f-0.03f)/(100.0f-1.0f)*(m_Intensity-1.0f)+0.03f;
	for(int i=0;i<size;++i)
	{
		int dHeight=(int)(deltaY*m_AdjustPointVector[i].ratio*intensityRatio);
		int currHeight=DataVector[i].prevHeight+dHeight;
		DataVector[i].currHeight=jlimit(0,65535,currHeight);
		WorldEditorRenderInterface::GetInstance()->GetWorldSystemManager()->setHeightMap(DataVector[i].index_x,\
			DataVector[i].index_z,DataVector[i].currHeight);
	}
	m_pVertexHeightOp2->FlushTerrainHeight();
}