AlloSphere-Research-Group / allolib

Library for interactive multimedia application development
BSD 3-Clause "New" or "Revised" License
36 stars 15 forks source link

Distributed/DynamicScene | communication between voice and app #23

Closed kybr closed 5 years ago

kybr commented 5 years ago

i'm looking at dynamic_scene.cpp and distributed_scene.cpp because i need to spatialize some sounds and AudioScene is broken and deprecated. these classes seem to be awesomely synthesiser-oriented, but my application does not quite fit that use-case.

[1] i need a way to communicate between voice and app. i see that the way to do this is with parameters. i could do something like this, but i don't like it:

gam::SamplePlayer samplePlayer[N]; // global
...
struct SimpleVoice : PositionedVoice {
  ParameterInt whichSound {"whichSound"};
...
 virtual void onProcess(AudioIOData& io) override {
        while(io()){
            io.out(0) = soundFile[whichSound]();
        }
    }
...
// later in the app...
           auto whichSound = std::vector<int>{0};
           freeVoice->setParamFields(whichSound);

[2] this means that in the main apps onDraw, i would like to iterate through each active voice, querying its pose:

Mesh mesh;
Texture texture;
...
virtual void onDraw(Graphics& g) override {
  ...
  texture.bind();
  for (auto& v : scene.activeVoices()) {
    g.pushMatrix();
    g.translate(v.pos());
    g.rotate(v.quat());
    g.draw(mesh);
    g.popMatrix();
  }
  texture.unbind();
}
...

is there something like scene.activeVoices()??

kybr commented 5 years ago

i have something working: https://github.com/yujnkm/MAT201B-yujnkm/blob/master/FinalProject/sketch-eyes-sound-background.cpp

i use userData() to get to the shared resource and onTriggerOn() together with a parameter to load specific sound files.

mantaraya36 commented 5 years ago

Thanks. Based on your example, I have written this new dynamic scene example to show userData() and always on voices https://github.com/AlloSphere-Research-Group/allolib/blob/aa83098634da6c164e4cd80251c8edde87d2310d/examples/ui/dynamic_scene2.cpp