[Solved] Printing a String Array into a label/TextEditor?


#1

Hi,

I've taken a break from C++ for years and have gotten curious again.

i'm trying to edit the [url=http://www.lifeorange.com/SOFTWARE/audiocpptutorial.html]AM FM MIDI Example[/url] over at www.lifeorange.com. I'm guessing I'll need a for loop but I've forgotten to syntax needed to put an array of anything into string form and into something like a label.

I'm to replace:

//FYI juce::MidiInput* midiInput

midiInput = MidiInput::openDevice(MidiInput::getDefaultDeviceIndex(), this);
std::cout<< "midi dev index = " << MidiInput::getDefaultDeviceIndex();

with this: (updated code)

controlChange = false;
	textEditor1.setMultiLine(true, true);
	//textEditor1.setReadOnly(true);
	textEditor1.setCaretVisible(true);
	textEditor1.setScrollbarsShown(true);
	textEditor1.setColour(TextEditor::outlineColourId, Colours::black);
	textEditor1.setColour(TextEditor::backgroundColourId, Colours::limegreen);
	addAndMakeVisible(&textEditor1);
	textEditor1.setSize(400, 200);

	const int devices = midiInput->getDevices().size();
	std::vector myMidiDevices(devices); 
	for (int j = 0; j < devices; j++)
	{
		textEditor1.insertTextAtCaret(String(myMidiDevices[j]));
		textEditor1.moveCaretDown(true);
	}

I know that this is horribly wrong. I've tried other things, can't seem to get it right. Could someone please help? smiley

 

Malik

 


#2

Got this far over the night, but the TextEditor shows nothing:


controlChange = false;
    textEditor1.setMultiLine(true, true);
    //textEditor1.setReadOnly(true);
    textEditor1.setCaretVisible(true);
    textEditor1.setScrollbarsShown(true);
    textEditor1.setColour(TextEditor::outlineColourId, Colours::black);
    textEditor1.setColour(TextEditor::backgroundColourId, Colours::limegreen);
    addAndMakeVisible(&textEditor1);
    textEditor1.setSize(400, 200);
    const int devices = midiInput->getDevices().size();
    std::vector<String> myMidiDevices(devices); 
    for (int j = 0; j < devices; j++)
    {
        textEditor1.insertTextAtCaret(String(myMidiDevices[j]));
        textEditor1.moveCaretDown(true);
    }

#3

ah got it.

:)


StringArray devices = midiInput->getDevices();
    const int devicesSize = midiInput->getDevices().size();
    std::vector<String> myMidiDevices(devicesSize); 
    for (int j = 0; j < devicesSize; j++)
    {
        textEditor1.insertTextAtCaret(String(devices[j]));
        textEditor1.moveCaretDown(true);
    }

#4

Or:

for (const String& d: midiInput->getDevices())
{
    textEditor1.insertTextAtCaret (d);
    textEditor1.moveCaretDown (true);
}

 


#5

Or even:

textEditor1.insertTextAtCaret (MidiInput::getDevices().joinIntoString (newLine));
textEditor1.moveCaretDown (true);

:)


#6

Clean!

Thanks guys. :)