예제 #1
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());
    }
}
예제 #2
0
    void mouseDrag (const MouseEvent& e) override
    {
        if (auto* m = owner.getModel())
        {
            if (isEnabled() && e.mouseWasDraggedSinceMouseDown() && ! isDragging)
            {
                SparseSet<int> rowsToDrag;

                if (owner.selectOnMouseDown || owner.isRowSelected (row))
                    rowsToDrag = owner.getSelectedRows();
                else
                    rowsToDrag.addRange (Range<int>::withStartAndLength (row, 1));

                if (rowsToDrag.size() > 0)
                {
                    auto dragDescription = m->getDragSourceDescription (rowsToDrag);

                    if (! (dragDescription.isVoid() || (dragDescription.isString() && dragDescription.toString().isEmpty())))
                    {
                        isDragging = true;
                        owner.startDragAndDrop (e, rowsToDrag, dragDescription, true);
                    }
                }
            }
        }

        if (! isDraggingToScroll)
            if (auto* vp = owner.getViewport())
                isDraggingToScroll = vp->isCurrentlyScrollingOnDrag();
    }
예제 #3
0
    //==============================================================================
    void syncSelectedItemsWithDeviceList (const ReferenceCountedArray<MidiDeviceListEntry>& midiDevices)
    {
        SparseSet<int> selectedRows;
        for (int i = 0; i < midiDevices.size(); ++i)
            if (midiDevices[i]->inDevice != nullptr || midiDevices[i]->outDevice != nullptr)
                selectedRows.addRange (Range<int> (i, i+1));

        lastSelectedItems = selectedRows;
        updateContent();
        setSelectedRows (selectedRows, dontSendNotification);
    }
    void mouseDrag (const MouseEvent& e) override
    {
        if (isEnabled() && owner.getModel() != nullptr && ! (e.mouseWasClicked() || isDragging))
        {
            SparseSet<int> rowsToDrag;

            if (owner.selectOnMouseDown || owner.isRowSelected (row))
                rowsToDrag = owner.getSelectedRows();
            else
                rowsToDrag.addRange (Range<int>::withStartAndLength (row, 1));

            if (rowsToDrag.size() > 0)
            {
                const var dragDescription (owner.getModel()->getDragSourceDescription (rowsToDrag));

                if (! (dragDescription.isVoid() || (dragDescription.isString() && dragDescription.toString().isEmpty())))
                {
                    isDragging = true;
                    owner.startDragAndDrop (e, rowsToDrag, dragDescription, true);
                }
            }
        }
    }
예제 #5
0
void CDPlayer::timerCallback()
{
    m_digitalDisplay.setText(Utils::formatSeconds(m_transportSource.getCurrentPosition()), sendNotification);

    int64 currentSample = m_source->getNextReadPosition();

    const Array<int>& offsets = m_reader->getTrackOffsets();
    // offsets[0] != 0 is possible, there might be a track before the first.
    // offsets.getLast() is not the start of the last track but the end sample of the CD.

    if (currentSample < offsets[0])
    {
        // We are before the first track.
        m_slider.setEnabled(false);
        m_slider.setValue(m_slider.getMinimum(), juce::dontSendNotification);
        m_currentTrack = -1;
        SparseSet<int> rows;
        m_tracksTable.setSelectedRows(rows, juce::dontSendNotification);
        return;
    }

    if (m_currentTrack == -1)
    {
        // We have now entered the first track.
        m_slider.setEnabled(true);
        m_slider.setRange(offsets[0], offsets[1]);
        // Possible loss of precision is acceptable for very large values because user can't select specific value that precise.
        m_slider.setValue(static_cast<double>(currentSample), juce::dontSendNotification);
        m_currentTrack = 0;
        m_pluginLoader.playlistEntrySelected(getName().toRawUTF8(), m_currentTrack);
        SparseSet<int> rows;
        rows.addRange(Range<int>(m_currentTrack, m_currentTrack + 1));
        m_tracksTable.setSelectedRows(rows, juce::dontSendNotification);
        return;
    }

    jassert(m_currentTrack + 1 < offsets.size());

    if (currentSample >= offsets[m_currentTrack] && currentSample < offsets[m_currentTrack + 1])
    {
        // We are still within the current track (usual case).
        // Possible loss of precision is acceptable for very large values because user can't select specific value that precise.
        m_slider.setValue(static_cast<double>(currentSample), juce::dontSendNotification);
        return;
    }

    // We are within another track.

    int64 firstSample = -1;
    int64 lastSample = -1;

    if (currentSample < offsets[m_currentTrack])
    {
        // We are before the curren track. Search backward to find the track our sample position now lies within.

        // Assume our current track is the immediately preceeding track.
        jassert(m_currentTrack - 1 >= 0);
        firstSample = -1;
        lastSample = offsets[m_currentTrack];

        for (int probeTrack = m_currentTrack - 1; probeTrack >= 0; --probeTrack)
        {
            if (currentSample >= offsets[probeTrack])
            {
                m_currentTrack = probeTrack;
                firstSample = offsets[probeTrack];
                break; // We are at the previous track.
            }

            lastSample = offsets[probeTrack];
        }

        m_pluginLoader.previousEntrySelected(getName().toRawUTF8());
        m_pluginLoader.playlistEntrySelected(getName().toRawUTF8(), m_currentTrack);
    }

    if (currentSample >= offsets[m_currentTrack + 1])
    {
        // We are after the curren track. Search forward to find the track our sample position now lies within.

        // Assume our current track is the immediately following track.
        jassert(m_currentTrack + 2 < offsets.size());
        firstSample = offsets[m_currentTrack + 1];
        lastSample = -1;

        for (int probeTrack = m_currentTrack + 2; probeTrack < offsets.size(); ++probeTrack)
        {
            if (offsets[probeTrack] > currentSample)
            {
                m_currentTrack = probeTrack - 1;
                lastSample = offsets[probeTrack];
                break; // We are at the next track.
            }

            firstSample = offsets[probeTrack];
        }

        m_pluginLoader.nextEntrySelected(getName().toRawUTF8());
        m_pluginLoader.playlistEntrySelected(getName().toRawUTF8(), m_currentTrack);
    }

    jassert(currentSample >= firstSample);
    jassert(currentSample < lastSample);

    // Possible loss of precision is acceptable for very large values because user can't select specific value that precise.
    m_slider.setRange(static_cast<double>(firstSample), static_cast<double>(lastSample));
    m_slider.setValue(static_cast<double>(currentSample), juce::dontSendNotification);
    SparseSet<int> rows;
    rows.addRange(Range<int>(m_currentTrack, m_currentTrack + 1));
    m_tracksTable.setSelectedRows(rows, juce::dontSendNotification);
    m_pluginLoader.positionChanged(getName().toRawUTF8(), m_transportSource.getCurrentPosition());
}