Organising a Large A-V Performance Sketch - Should I make Classes? Memory Management

Hi All,

I’m developing a A-V performance and have a question about how to best structure it.

I’m using TouchOSC on an iPad to control various parameters (MIDI to external audio gear, and OSC to Processing for visual). Please see the screenshot.

The question is around the top left section - 16 “banks” A-P each containing 16 “patterns” (1-16).

Let’s think of each bank as a song - each “song” (Bank A-P) will have an overall aesthetic, distinct from the other “songs”, but with some shared characteristics.

Let’s say song 1 (BankA) has a blue background, song 2 (BankB) has a blue background and song 3 (BankC) has a red background. Obz in actuality each song will have more complex differences and similarities, but I hope the point is clear.

Should I make a “Bank” Class?

Secondarily, as “children” of each bank are 16 patterns - these will derive in part from their parents, but each will also be distinct. For example,
(if Bank A=true)
pattern 1 will have a black rect, pattern 2 a white circle, pattern 3 a yellow triangle… etc…
(if Bank B=true)
pattern 1 will show an image, pattern 2 movie x, pattern 3 movie y… etc
Bank C etc…
Bank D etc…
etc…
etc…

Should I make a “Pattern” Class?

Do I also need to anticipate memory issues? - loading many images (potentially hundreds, not thousands) and videos (2K resolution, < 50 movies in all) depending upon the bank, and pattern selected. How should I unload images and movies from memory if they are not currently in use?

I’m doing something way beyond my coding chops, learning a lot along the way, and any advice would be muchly appreciated.

Hi @JonnieNightTime :slight_smile:

I’m not an expert but it seems to make sense to structure your code that way. I feel there might be more behind your question though. Why are you asking if you should use classes?

For your question about memory, this might be helpful:

1 Like

HI sableRaph,

The question about classes is about the “best” way to go about this.

For example, in my main sketch, I’ve got as far as this = Bank A, Patterns 1 and 2 - a nested loop for each of the 16 banks, each bank containing its 16 patterns - see example below. If I repeat this structure for a patterns (A) 3-16, and then repeat that overall Bank A structure for banks B-P it’s going to develop into some pretty long code.

Is there any particular issue should I go in this direction - like, something like latency as the program loops through all those conditions before finding whatever condition happens to be being meet at that moment e.g. Bank P Pattern 7?

Would classes be, by their nature, more efficient somehow?

  if(Bank == 0){ /////////////////////////////////////////////////////////////////////////////  BANK A - make a Bank class?
  
      fill(#000000, BankTransparency[0]++);  ////// Bank Title Text Fade In
      text (BankTxt[0], width/2, height/3); 
      
      BankTransparency[1] = 0; BankTransparency[2] = 0; BankTransparency[3] = 0; BankTransparency[4] = 0;  BankTransparency[5] = 0; BankTransparency[6] = 0; 
      BankTransparency[7] = 0; BankTransparency[8] = 0; BankTransparency[9] = 0; BankTransparency[10] = 0; BankTransparency[11] = 0; BankTransparency[12] = 0; 
      BankTransparency[13] = 0; BankTransparency[14] = 0; BankTransparency[15] = 0; /// Other Banks faded out
      
       /// lots more cool stuff here for Bank A
      
      if(Pattern == 0){ /////////////////////////////////////////////////////////////// PATTERN 1 - make a Pattern Class?
      
        fill(#000000, PatternTransparency[0]++);  ////// Pattern Title Text Fade In  
        text(Pattern+1, width/2 + 40, height/3);  ///// Pattern Title Text
      
        BankTransparency[1] = 0; BankTransparency[2] = 0; BankTransparency[3] = 0; BankTransparency[4] = 0;  BankTransparency[5] = 0; BankTransparency[6] = 0; 
        BankTransparency[7] = 0; BankTransparency[8] = 0; BankTransparency[9] = 0; BankTransparency[10] = 0; BankTransparency[11] = 0; BankTransparency[12] = 0; 
        BankTransparency[13] = 0; BankTransparency[14] = 0; BankTransparency[15] = 0; /// Other Patterns faded out
        
         /// lots more cool stuff here for Pattern (A)1 
     
      }
      
      if(Pattern == 1){ /////////////////////////////////////////////////////////////// PATTERN 2
        
        fill(#000000, PatternTransparency[1]++);  ////// Pattern Title Text Fade In
        text(Pattern+1, width/2 + 40,height/3 );  ///// Pattern Title Text
        
        BankTransparency[0] = 0; BankTransparency[2] = 0; BankTransparency[3] = 0; BankTransparency[4] = 0;  BankTransparency[5] = 0; BankTransparency[6] = 0; 
        BankTransparency[7] = 0; BankTransparency[8] = 0; BankTransparency[9] = 0; BankTransparency[10] = 0; BankTransparency[11] = 0; BankTransparency[12] = 0; 
        BankTransparency[13] = 0; BankTransparency[14] = 0; BankTransparency[15] = 0; /// Other Patterns faded out
        
             /// lots more cool stuff here for Pattern (A)2 

      }

I’m not a computer scientist, but I can’t imagine that just a few if statements will slow your code down, especially if you only need to run these checks when manually changing bank or pattern. Computers are fast :wink:

What I can say is that there seems to be a lot of redundancy in your current code so using classes might help you make your code shorter.

A possible approach would be to build a minimal version of what you want. Say a bank can be on or off, a pattern can have one property and two methods (one to set and one to get that single property). Leaving out the finer details. Then you can start adding more functionality. At least that’s how I might go about it.

3 Likes

I’ll add one thing. It’s great to plan and try do things right, but don’t be afraid to experiment. Even if things break or run slow, you can always fix it. If you need to, you can save a copy of your latest running version to give you the confidence that you can always go back. Eventually, learning how to use version tracking (like Git) might be a good use of your time for the same reason :wink:

3 Likes

hi sableRaph,

Sorry for the delay in responding - many thanks for your good advice.

Best wishes and Nadolig Llawen :-))

1 Like