activate sounds with ofxGuiMatrix

Hallo all around the OF-Community!

Despite I´m very new to programming it seems to me that OF allows to get into it
quite intuitively and holds many wonderfull opportunities. I´ve read through the
forum many times and made my journey through some examples trying to modify
them.

Unfortunately I´m stuck now with a certain problem and need some help. I wanted
to use the matrix of ofxGui (credits to Bilderbuchi!) to control an array of sounds,
so that if I click a matrix cell a certain sound from the array starts playing. My
project includes ofXmlSettings, ofxGui and ofxDirList. I tried to make an array of
soundfiles and load them like this:

  
nSounds = DIR.listDir("sounds");  
 	sounds = new ofSoundPlayer[nSounds];  
      
    for(int i = 0; i < nSounds; i++){  
            sounds[i].loadSound(DIR.getPath(i));}  

Now I want to pass the soundfiles to the buttons of the matrix in ofxGui. So i did
something like:

  
for(int i=0;i<nSounds; i++){  
  
	for(int i = 0; i < mYGrid; i++)  
	{  
		for(int j = 0; j < mXGrid; j++)  
		{  
			nSounds = kofxGui_Matrix_Set;   
  
			}  
		}  
	}  

…and to get them playing I tried to type in this in ofxGuiMatrix.cpp:

  
testApp::handleGui(int parameterId, int task, void* data, int length){  
	switch(parameterId){  
  
	case matrix:  
		if (task == kofxGui_Set_Cell){  
  
	sounds[0].play();}  

…but that (and some similar ideas) didn’t work. ?Maybe I have to declare a
gridarray first like

  
int gridarray[mYGrid][mxGrid] // ??  

But that didn`t work either. I also tried calling:

  
gui->update(matrix, kofxGui_Set_Cell, &sounds, sizeof(float*));  

Well, what I do here might seem quite naive. :roll: Obviously I`m reaching the
limits of “intuitive coding” at this point. I´m seriously motivated to work some
ideas out, so I just started to get deaper into C++, but the complexitiy of ofxGui
isn´t easy to understand.

I don´t know how to solve this problem. Maybe some of you have ideas and could take a minute to explain how to work this out?

Thanks in advance and greetings all around the world from Berlin!

Ron

welcome!
the credits are actually not for me, i haven’t written ofxGUI, but stivo did. i just decided to host it (and maybe make improvements) so it’s available to a better audience. :slight_smile:
Anyways, I gotta run, maybe I can look at this later, but I’m quite busy for the weekend.

I’d suggest you should try to be able to play sounds at all (i.e. confirm that the line above works), and then try to get it to play at any matrix button press (that seems what you try to do, anyways), then try to play different sounds. via (maybe) sounds[*(int*)data].play; or something similar.

Yeah! Thank you very much, Bilderbuchi, in fact sounds[*(int*)data].play(); did it!
Dear, its been so easy... I just turned the whole upside down, means I didnd
think about passing the matixvalue to the soundarray, instead I somehow wanted to pass the elements of the soundarray to the matrix… or something like that :wink:

Community on!

Ron

glad to hear it worked. :slight_smile: