Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Collaborative Step-Sequencer

Discussion in 'Works In Progress' started by Jason Harron, Feb 19, 2015.

  1. Jason Harron

    Jason Harron

    Joined:
    Feb 19, 2015
    Posts:
    10
    **Update 3/8/2015 - First Complete build is online

    Hi everybody,

    I'm currently trying to create a step-sequencer in Unity where multiple people can log-in at once and collaborate making music/noise.

    The current build of my project: http://tinyurl.com/collaborativesoundscape

    At this moment it is only single-player. I am currently stuck trying to figure out how to do several things:
    1) Synchronize time between multiple computers
    2) When one person clicks on their block, to send the data to the other computers connected (whether server or client) to tell everybody's Unity scenes to change that block.
    3) In a perfect world, I'd also like the server to write the current blocks to a database, so upon load the "soundscape" is not loss. That way it will change over time, and I can also look back and see snapshots of the soundscape at any given time.

    If anybody has advice on how to get the mouse click of an object to change on both computers it would be greatly appreciated! In my mind it just seems like "Call this block a specific variable or name, and tell everybody the bool on that name just changed from true to false." or "In everybody's scenes, any block with the tag "Block 1-1" swap the bool." From the documentation I have read it seems like an RPC is the way to go since it only needs to send the current state of the variables upon connection and after each time a mouse clicks on a block.
     
    Last edited: Mar 8, 2015
  2. inko

    inko

    Joined:
    Nov 29, 2013
    Posts:
    143
    Whoa... just played 15 minutes straight with this thing :D

    I'm terribly unmusical but for some reason rythm editors like this always appealed to me. And having that synced over a server would be freakin awesome!

    So, now for your question. I don't know how much experience you have with networking, or coding in general, so I'll just post some code here with minor explanations. If you have a question, just ask :)

    I assume you have each cube storing its own sound clip while also handling its input? If you wanna keep that system you can try something like this:

    Code (CSharp):
    1.  
    2. class MusicNode {
    3.   bool active = true;
    4.   public void Tick () {
    5.     if(active) audio.Play();
    6.   }
    7.  
    8.   [RPC]
    9.   void AssignCurrent (bool b) {
    10.     active = b;
    11.     material.color = b ? Color.white : Color.blue;
    12.   }
    13.  
    14.   void OnMouseButtonDown () {   //this is a unity function and gets called on the gameObject without you having to call it yourself
    15.   networkView.RPC("AssignCurrent", RPCMode.All, b);
    16. //keep in mind that this will not work in offline mode. So either you need to simulate a server even when playing offline or you need to have a seperate call for that case
    17.   }
    18. }
    19.  
    But keep in mind that this way each cube would need its own networkView. For a small scale project thats no big deal, but if you want to add more complexity later on you may wanna consider a manager class.

    Code (CSharp):
    1.  
    2. class MusicNodeHandler {
    3.   public GameObject nodeCubes;
    4.   public AudioClip[] clips;
    5.   bool[] values = new bool[5];
    6.  
    7.   void Tick () {
    8.     for(int i=0;i<values;i++) {
    9.       if(values[i]) audio.Play( clips[i] );
    10.     }
    11.   }
    12.  
    13.   [RPC]
    14.   void AssignCurrent (int i, bool b) {
    15.     values[i] = b;
    16.     //then update their color
    17.     for(int n=0;n< nodeCubes.Length;n++) {
    18.       nodeCubes.material.color = (values[n]) ? Color.white : Color.blue;
    19.     }
    20.   }
    21. }
    22.  
    Here all the input for a node cell is funneled through a single function which keeps the code clean.
    So when you want to change the state of that cell all you need is to send an identifyer ID and the active state instead of handling each block individually.

    Righty, hope this helps clearing things up, keep it up!
     
    Jason Harron likes this.
  3. Jason Harron

    Jason Harron

    Joined:
    Feb 19, 2015
    Posts:
    10
    Inko, thanks for the response!

    Your sample code look much cleaner than the work-around I finally figured out. Due to my lack of experience I kept running in to dead-ends with the RPCMod.All. Turns out I was doing the call from within the RPC which resulted in an infinite loop.

    After many hacks and workarounds, it can now support multiple users! Next step is to expand it out to include multiple instruments, add user colors so you can see what blocks you changed, and make it so the soundscape will automatically load from a database so it will slowly change and evolve over time!

    I will definitely go back and try to clean-up the code and use some of your great suggestions to make the program more efficient.

    The new working collaborative version is online now at the same http://tinyurl.com/collaborativesoundscape

    Easy to see it in action if you log-in in two browsers. :)
     
  4. Jason Harron

    Jason Harron

    Joined:
    Feb 19, 2015
    Posts:
    10
    Full project is now online

    Link to Project: http://tinyurl.com/collaborativesoundscape

    Link to Development Blog: https://collaborativesoundscape.wordpress.com/

    For the past month I have been working on the creation of a collaborative step-sequencer using free tools such as Unity 4.6.2, PUN, and Audacity. The goal of the project is to allow up to 20 people to create music/noise together.

    The plan is to leave my computer logged in to program for the next 30 days to keep the soundscape from resetting. So, when you log in you'll see whatever the last person left there. All of the colored blocks in the step-sequence are linked to the users thought RPC over the Photon Network (PUN). There are two modes, Mode 1) "coloring" mode using glockenspiel for the sound, and Mode 2) "band" mode where each color is a different instrument. The modes are also connected via RPC so all users change mode at once.

    I also included a very simple data log at the top of the screen so you can see who made the last change. When you connect it randomly generates a number between 1 and 100 which is assigned as an Anonymous Animal name (like Google Docs.)

    Please give it a try! I'd love to get some feedback. The ultimate goal is to improve my skills at Unity3D / C# so I can develop better immersive learning environments as I work towards earning my Ph.D. in Education.
     
  5. Jason Harron

    Jason Harron

    Joined:
    Feb 19, 2015
    Posts:
    10
    Based on some feedback from Facebook friends I've added a Clear All button.
     
  6. Jason Harron

    Jason Harron

    Joined:
    Feb 19, 2015
    Posts:
    10
    Fixed another bug where it where is a player entered it would print that they changed the program to Mode 2. I'd love some feedback :)
     
  7. Jason Harron

    Jason Harron

    Joined:
    Feb 19, 2015
    Posts:
    10
    Project has been going well. I'd love to have more people try out the step-sequencer. Here is my first data visualization of the use of the program (1252 clicks)

    [​IMG]
     
  8. Jason Harron

    Jason Harron

    Joined:
    Feb 19, 2015
    Posts:
    10
    Here is a link to the original source files for my program. You'll need a free PUN account to make it work. It was designed in the free version of Unity3D 4.6.2, so it may not upgrade 100% to the newer version. Feel free to experiment/remix or ask any questions about the code.
     
  9. Jason Harron

    Jason Harron

    Joined:
    Feb 19, 2015
    Posts:
    10
    ColabDataVis - 3-26-2015.png

    Updated the data on my project. If you have not tried it, I'd love to collect some more data for my doctoral studies.

    I’ve begun crunching the data from this project. So far the Soundscape has received over 2,100 clicks by 41 users.

    A user has been defined as somebody who logs in to the program and makes at least one click. The average user makes over 52 clicks and uses the program for 3 min 22 sec. Time is measured from the users first click until their last click. If the user makers only one click they are given a time of zero since their first and last click have the same time.

    In a little over two weeks, users from around the globe have played with the program for over two hours of music creation.

    If you have a chance, give my step-sequencer a try. http://tinyurl.com/collaborativesoundscape

    Feedback is always welcome!