//==============================================================================
void MidiGrid::findLassoItemsInArea (Array<MidiGridItem*> &itemsFound, int x, int y, int width, int height)
{
#if 0
    const Rectangle lasso (x, y, width, height);
    for (int i = 0; i < notes.size (); i++)
    {
        MidiGridItem* note = notes.getUnchecked (i);
        if (note->getBounds().intersects (lasso))
        {
            itemsFound.addIfNotAlreadyThere (note);
            selectedNotes.addToSelection (note);
        }
        else
        {
            selectedNotes.deselect (note);
        }
    }
#endif

    for (int i = 0; i < notes.size (); i++)
    {
        MidiGridItem* note = notes.getUnchecked (i);
        if ((note->getX() >= x && note->getX() < x + width)
            && (note->getY() >= y && note->getY() < y + height))
        {
            itemsFound.addIfNotAlreadyThere (note);
            selectedNotes.addToSelection (note);
        }
        else
        {
            selectedNotes.deselect (note);
        }
    }
}
void AutomationGrid::findLassoItemsInArea (Array<MidiGridItem*> &itemsFound, int x, int y, int width, int height)
{
#if 0
    const Rectangle lasso (x, y, width, height);
    for (int i = 0; i < notes.size (); i++)
    {
        MidiGridItem* note = notes.getUnchecked (i);
        if (note->getBounds().intersects (lasso))
        {
            itemsFound.addIfNotAlreadyThere (note);
            selectedNotes.addToSelection (note);
        }
        else
        {
            selectedNotes.deselect (note);
        }
    }
#endif

    for (int i = 0; i < notes.size (); i++)
    {
        AutomationEvent* note = getEvent (i);
        if ((note->getX() >= x && note->getX() < x + width)
            && (note->getY() >= y && note->getY() < y + height)
			&& note->getController() == templateEvent.getController()) // overriding this method so we can only select events with same CC
        {
            itemsFound.addIfNotAlreadyThere (note);
            selectedNotes.addToSelection (note);
        }
        else
        {
            selectedNotes.deselect (note);
        }
    }
}
Example #3
0
String getFirstRecognizedChord(Array<int> chord, bool flats)
{
	if (chord.size()==0)
		return " ";
	if (chord.size()==2)
		return getIntervalName(chord[1]-chord[0]) + " ("+listNoteNames(chord,flats)+")";
	
	Array<int> temp;
	for (int i=0;i<chord.size();i++) {
		temp.addIfNotAlreadyThere(chord[i]%12);
	}

	if (temp.size()>=9)
		return getNoteNameWithoutOctave(chord[0],!flats)+" Note Soup";

	Array<int> stackedChord = getAsStackedChord(temp,false);
	if (stackedChord.size()==1)
		return "(" + getNoteNameWithoutOctave(stackedChord[0],!flats) + ")";

	String s = ChordName::getIntervalString(stackedChord);
	for (int i=0;i<ChordNames.size();i++)
	{
		if (ChordNames.getReference(i).equals2(s)) {
			return ChordNames.getReference(i).getName(stackedChord[ChordNames.getReference(i).getRootIndex()],chord[0],flats);
		}
	}
	return "("+listNoteNames(temp,flats)+")";// "Unknown chord";
}
Example #4
0
void MACAddress::findAllAddresses (Array<MACAddress>& result)
{
    const int s = socket (AF_INET, SOCK_DGRAM, 0);
    if (s != -1)
    {
        struct ifaddrs* addrs = nullptr;

        if (getifaddrs (&addrs) != -1)
        {
            for (struct ifaddrs* i = addrs; i != nullptr; i = i->ifa_next)
            {
                struct ifreq ifr;
                strcpy (ifr.ifr_name, i->ifa_name);
                ifr.ifr_addr.sa_family = AF_INET;

                if (ioctl (s, SIOCGIFHWADDR, &ifr) == 0)
                {
                    MACAddress ma ((const uint8*) ifr.ifr_hwaddr.sa_data);

                    if (! ma.isNull())
                        result.addIfNotAlreadyThere (ma);
                }
            }

            freeifaddrs (addrs);
        }

        close (s);
    }
}
void MACAddress::findAllAddresses (Array<MACAddress>& result)
{
    const int s = socket (AF_INET, SOCK_DGRAM, 0);
    if (s != -1)
    {
        char buf [1024];
        struct ifconf ifc;
        ifc.ifc_len = sizeof (buf);
        ifc.ifc_buf = buf;
        ioctl (s, SIOCGIFCONF, &ifc);

        for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
        {
            struct ifreq ifr;
            strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);

            if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
                 && (ifr.ifr_flags & IFF_LOOPBACK) == 0
                 && ioctl (s, SIOCGIFHWADDR, &ifr) == 0)
            {
                result.addIfNotAlreadyThere (MACAddress ((const uint8*) ifr.ifr_hwaddr.sa_data));
            }
        }

        close (s);
    }
}
Example #6
0
//------------------------------------------------------------------------------
static void getDeviceBufferSizes (snd_pcm_t* handle, Array<uint>& bufSizes)
{
    snd_pcm_hw_params_t* hwParams;
    snd_pcm_hw_params_alloca (&hwParams);

    if (snd_pcm_hw_params_any (handle, hwParams) >= 0)
    {
        int dir = 0;
        snd_pcm_uframes_t minSize = 0, maxSize = 0;
        snd_pcm_hw_params_get_period_size_min (hwParams, &minSize, &dir);
        snd_pcm_hw_params_get_period_size_max (hwParams, &maxSize, &dir);

        minSize = jmax(nextPowerOfTwo(minSize), 16);
        maxSize = jmin(maxSize, 8192U);

        for (snd_pcm_uframes_t s = minSize; s <= maxSize; s = nextPowerOfTwo(s+1))
        {
            if (snd_pcm_hw_params_test_period_size (handle, hwParams, minSize, dir) == 0)
                bufSizes.addIfNotAlreadyThere (s);

            if (s == 8192)
                break;
        }
    }

    //snd_pcm_hw_params_free (hwParams);
}
Example #7
0
static Array<File> getAllPossibleModulePathsFromExporters (Project& project)
{
    StringArray paths;

    for (Project::ExporterIterator exporter (project); exporter.next();)
    {
        auto& modules = project.getModules();
        auto n = modules.getNumModules();

        for (int i = 0; i < n; ++i)
        {
            auto id = modules.getModuleID (i);

            if (modules.shouldUseGlobalPath (id))
                continue;

            const auto path = exporter->getPathForModuleString (id);

            if (path.isNotEmpty())
                paths.addIfNotAlreadyThere (path);
        }

        String oldPath (exporter->getLegacyModulePath());

        if (oldPath.isNotEmpty())
            paths.addIfNotAlreadyThere (oldPath);
    }

    Array<File> files;

    for (auto& path : paths)
    {
        auto f = project.resolveFilename (path);

        if (f.isDirectory())
        {
            files.addIfNotAlreadyThere (f);

            if (f.getChildFile ("modules").isDirectory())
                files.addIfNotAlreadyThere (f.getChildFile ("modules"));
        }
    }

    return files;
}
Example #8
0
Array<int> getAsStackedChord(Array<int> &chord, bool reduce)
{
	Array<int> temp;
	if (reduce) {
		//remove duplicate notes
		for (int i=0;i<chord.size();i++) {
			temp.addIfNotAlreadyThere(chord[i]%12);
		}
		if (temp.size()==1)
			return temp;
	}
	else
		temp.addArray(chord);

	//sort 
	DefaultElementComparator<int> intsorter;
	temp.sort(intsorter);

	int Minimum = -1;
	//the base chord is the one with the minimal energy function
	//the energy function is the sum of the number of half steps between successive notes in the chord
	//hence, the canonic chord is the chord in which the notes lie as closely spaced as possible
	Array<PizChord> MinimumEnergyChordList;

	PizChord tempChord0(temp);
	//DBG("permutation: " + tempChord0.getStringPattern());
	Minimum = tempChord0.getSum();
	MinimumEnergyChordList.add(tempChord0);

	while(std::next_permutation(temp.begin(),temp.end()))
	{
		PizChord tempChord(temp);
		//DBG("permutation: " + tempChord.getStringPattern());
		int S = tempChord.getSum();
		if (S < Minimum || Minimum == -1) 
		{
			//new minimum found => discard what we found up to now
			Minimum = S;
			MinimumEnergyChordList.clear();
			MinimumEnergyChordList.add(tempChord);
		}
		else if (S==Minimum)
		{
			//another chord with minimum energy => add it to the list
			MinimumEnergyChordList.add(tempChord);
		}
	}
	//now we face a problem: multiple minimum energy chords can exist if more than 3 notes are present
	//we need a way of picking one chord that will always lead to the same interval pattern, no matter
	//what note names are used. Normal "sort" will sort alphabetically. This is unusable.
	//We need to sort on the interval patterns instead, but return the chord that corresponds to the pattern.
	DefaultElementComparator<PizChord> sorter;
	MinimumEnergyChordList.sort(sorter);
	//DBG("picked" + MinimumEnergyChordList.getFirst().getStringPattern());
	return MinimumEnergyChordList.getFirst().getChord();
}
Example #9
0
void uniqueIntArray (Array <int> &arrayToModify)
{
	Array<int> temp;
	for (int i=0; i<arrayToModify.size(); i++)
	{
		temp.addIfNotAlreadyThere(arrayToModify[i]);
	}

	arrayToModify.swapWith (temp);
}
Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
{
    Array<int> results;
    const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
    const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };

    for (int i = 0; i < numElementsInArray (speeds); ++i)
        if (speeds[i] <= maxSpeed)
            results.add (speeds[i]);

    results.addIfNotAlreadyThere (maxSpeed);
    return results;
}
Example #11
0
void TooltipWindow::displayTip (Point<int> screenPos, const String& tip)
{
    jassert (tip.isNotEmpty());

    if (! reentrant)
    {
        ScopedValueSetter<bool> setter (reentrant, true, false);

        if (tipShowing != tip)
        {
            tipShowing = tip;
            repaint();
        }

        if (auto* parent = getParentComponent())
        {
            updatePosition (tip, parent->getLocalPoint (nullptr, screenPos),
                            parent->getLocalBounds());
        }
        else
        {
            updatePosition (tip, screenPos, Desktop::getInstance().getDisplays()
                                                .getDisplayContaining (screenPos).userArea);

            addToDesktop (ComponentPeer::windowHasDropShadow
                            | ComponentPeer::windowIsTemporary
                            | ComponentPeer::windowIgnoresKeyPresses
                            | ComponentPeer::windowIgnoresMouseClicks);
        }

       #if JUCE_DEBUG
        activeTooltipWindows.addIfNotAlreadyThere (this);

        for (auto* w : activeTooltipWindows)
        {
            if (w != this && w->tipShowing == tipShowing)
            {
                // Looks like you have more than one TooltipWindow showing the same tip..
                // Be careful not to create more than one instance of this class!
                jassertfalse;
            }
        }
       #endif

        toFront (false);
    }
}
//==================================================================================================================
void ComponentLayoutEditor::findLassoItemsInArea (Array <ComponentOverlay*>& results, const Rectangle<int>& area)
{
    const Rectangle<int> lasso (area);

    for (int i = 0; i < getNumChildComponents() - 1; i++)
    {
        ComponentOverlay* c = (ComponentOverlay*)getChildComponent (i);

        if (c->getBounds().intersects (lasso))
        {
            results.addIfNotAlreadyThere (c);
            selectedComponents.addToSelection (c);
        }
        else
            selectedComponents.deselect (c);
    }
}
//==============================================================================
void GraphComponent::findLassoItemsInArea (Array<GraphNodeComponent*> &itemsFound, int x, int y, int width, int height)
{
    for (int i = 0; i < nodes.size (); i++)
    {
        GraphNodeComponent* node = nodes.getUnchecked (i);
        if ((node->getX() >= x && node->getX() < x + width)
             && (node->getY() >= y && node->getY() < y + height))
        {       
            itemsFound.addIfNotAlreadyThere (node);
            selectedNodes.addToSelection (node);
        }
        else
        {
            selectedNodes.deselect (node);
        }
    }
}
Example #14
0
    void getViaNetBios (Array<MACAddress>& result)
    {
        DynamicLibrary dll ("netapi32.dll");
        JUCE_LOAD_WINAPI_FUNCTION (dll, Netbios, NetbiosCall, UCHAR, (PNCB))

        if (NetbiosCall != 0)
        {
            LANA_ENUM enums = { 0 };

            {
                NCB ncb = { 0 };
                ncb.ncb_command = NCBENUM;
                ncb.ncb_buffer = (unsigned char*) &enums;
                ncb.ncb_length = sizeof (LANA_ENUM);
                NetbiosCall (&ncb);
            }

            for (int i = 0; i < enums.length; ++i)
            {
                NCB ncb2 = { 0 };
                ncb2.ncb_command = NCBRESET;
                ncb2.ncb_lana_num = enums.lana[i];

                if (NetbiosCall (&ncb2) == 0)
                {
                    NCB ncb = { 0 };
                    memcpy (ncb.ncb_callname, "*                   ", NCBNAMSZ);
                    ncb.ncb_command = NCBASTAT;
                    ncb.ncb_lana_num = enums.lana[i];

                    struct ASTAT
                    {
                        ADAPTER_STATUS adapt;
                        NAME_BUFFER    NameBuff [30];
                    };

                    ASTAT astat = { 0 };
                    ncb.ncb_buffer = (unsigned char*) &astat;
                    ncb.ncb_length = sizeof (ASTAT);

                    if (NetbiosCall (&ncb) == 0 && astat.adapt.adapter_type == 0xfe)
                        result.addIfNotAlreadyThere (MACAddress (astat.adapt.adapter_address));
                }
            }
        }
    }
Example #15
0
//------------------------------------------------------------------------------
static void getDeviceSampleRates (snd_pcm_t* handle, Array<double>& rates)
{
    const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };

    snd_pcm_hw_params_t* hwParams;
    snd_pcm_hw_params_alloca (&hwParams);

    for (int i = 0; ratesToTry[i] != 0; ++i)
    {
        if (snd_pcm_hw_params_any (handle, hwParams) >= 0
             && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
        {
            rates.addIfNotAlreadyThere ((double) ratesToTry[i]);
        }
    }

    //snd_pcm_hw_params_free (hwParams);
}
Example #16
0
const bool CtrlrPanel::checkRadioGroup(CtrlrComponent *c, const bool componentToggleState)
{
	if (c->isToggleButton())
	{
		const int groupId = c->getProperty (Ids::componentRadioGroupId);
		if (groupId > 0)
		{
			Array <ComponentReference> componentsToRemove;

			for (int i=0; i<radioGrouppedComponent.size(); i++)
			{
				if (radioGrouppedComponent[i].wasObjectDeleted())
				{
					componentsToRemove.addIfNotAlreadyThere (radioGrouppedComponent[i]);
				}
				else
				{
					if (
							(int)radioGrouppedComponent[i]->getProperty(Ids::componentRadioGroupId) == groupId
							&& radioGrouppedComponent[i]->getToggleState() == componentToggleState
							&& radioGrouppedComponent[i].get() != c
							&& componentToggleState == true
						)
					{
						/* need to change that state, only one in the group can have this state */
						radioGrouppedComponent[i]->setToggleState(false);
						radioGrouppedComponent[i]->getOwner().setProperty (Ids::modulatorValue, false);
					}
					else if (
								componentToggleState == false
								&& radioGrouppedComponent[i].get() == c
							)
					{
						c->setToggleState (true, false);
					}
				}
			}
		}
	}

	return (true);
}
Example #17
0
static Array<File> getAllPossibleModulePaths (Project& project)
{
    StringArray paths;

    for (Project::ExporterIterator exporter (project); exporter.next();)
    {
        if (exporter->mayCompileOnCurrentOS())
        {
            for (int i = 0; i < project.getModules().getNumModules(); ++i)
            {
                const String path (exporter->getPathForModuleString (project.getModules().getModuleID (i)));

                if (path.isNotEmpty())
                    paths.addIfNotAlreadyThere (path);
            }

            String oldPath (exporter->getLegacyModulePath());

            if (oldPath.isNotEmpty())
                paths.addIfNotAlreadyThere (oldPath);
        }
    }

    Array<File> files;

    for (int i = 0; i < paths.size(); ++i)
    {
        const File f (project.resolveFilename (paths[i]));

        if (f.isDirectory())
        {
            files.add (f);

            if (f.getChildFile ("modules").isDirectory())
                files.addIfNotAlreadyThere (f.getChildFile ("modules"));
        }
    }

    return files;
}
Example #18
0
void ScriptContentComponent::getScriptComponentsFor(Array<ScriptingApi::Content::ScriptComponent*> &arrayToFill, const Rectangle<int> area)
{
	arrayToFill.clear();

	for (int i = componentWrappers.size() - 1; i >= 0; --i)
	{
		auto sc = contentData->getComponent(i);

		Component* c = componentWrappers[i]->getComponent();

		if (sc == nullptr || !sc->isShowing())
			continue;

		Component* parentOfC = c->getParentComponent();

		auto cBounds = getLocalArea(parentOfC, c->getBounds());


		if (area.contains(cBounds))
		{
			arrayToFill.addIfNotAlreadyThere(sc);
		}
	}
}