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

**URL:** <https://discourse.processing.org/t/organising-a-large-a-v-performance-sketch-should-i-make-classes-memory-management/39943>\
**Category:** Libraries\
**Created:** [November 30, 2022, 1:34pm UTC](https://discourse.processing.org/t/organising-a-large-a-v-performance-sketch-should-i-make-classes-memory-management/39943 "2022-11-30T13:34:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonnieNightTime](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@JonnieNightTime](https://discourse.processing.org/u/JonnieNightTime)\
**Post date:** [November 30, 2022, 1:34pm UTC](https://discourse.processing.org/t/organising-a-large-a-v-performance-sketch-should-i-make-classes-memory-management/39943/1 "2022-11-30T13:34:11Z")

</div>

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.

 ![Screenshot 2022-11-30 at 13.02.29](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/4/14a8db9153619dcccc7383e2132348eb68c6040e.png)

---

<div class="post-metadata">

**Author:** ![sableraph](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sableraph/32/251_2.png) [@sableraph](https://discourse.processing.org/u/sableraph)\
**Post date:** [November 30, 2022, 4:11pm UTC](https://discourse.processing.org/t/organising-a-large-a-v-performance-sketch-should-i-make-classes-memory-management/39943/2 "2022-11-30T16:11:03Z")

</div>

Hi @JonnieNightTime 🙂

> [@JonnieNightTime](#):
>
> Should I make a “Bank” Class?

> [@JonnieNightTime](#):
>
> Should I make a “Pattern” Class?

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:

> [@Optimizing for memory with images](https://discourse.processing.org/t/optimizing-for-memory-with-images/25772/9):
>
> Hi, I can clearly see that it’s starting to make sense! Indeed it’s exactly what I (and others, @micycle @noel ) were suggesting. wink Note that the garbage collector is not instantly releasing a previous overwritten PImage. It’s up to the JVM (Java virtual machine, running the bytecode produced by the Java compiler) to decide when to free the previous image. Anyway it’s going to greatly reduce memory usage! I found those useful StackOverflow links about garbage collector and how to dea…

---

<div class="post-metadata">

**Author:** ![JonnieNightTime](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@JonnieNightTime](https://discourse.processing.org/u/JonnieNightTime)\
**Post date:** [December 1, 2022, 1:53pm UTC](https://discourse.processing.org/t/organising-a-large-a-v-performance-sketch-should-i-make-classes-memory-management/39943/3 "2022-12-01T13:53:46Z")

</div>

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?

```auto
  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 

      }

```

---

<div class="post-metadata">

**Author:** ![sableraph](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sableraph/32/251_2.png) [@sableraph](https://discourse.processing.org/u/sableraph)\
**Post date:** [December 1, 2022, 3:24pm UTC](https://discourse.processing.org/t/organising-a-large-a-v-performance-sketch-should-i-make-classes-memory-management/39943/4 "2022-12-01T15:24:29Z")

</div>

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 😉

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.

---

<div class="post-metadata">

**Author:** ![sableraph](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sableraph/32/251_2.png) [@sableraph](https://discourse.processing.org/u/sableraph)\
**Post date:** [December 1, 2022, 3:35pm UTC](https://discourse.processing.org/t/organising-a-large-a-v-performance-sketch-should-i-make-classes-memory-management/39943/5 "2022-12-01T15:35:38Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![JonnieNightTime](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@JonnieNightTime](https://discourse.processing.org/u/JonnieNightTime)\
**Post date:** [December 15, 2022, 4:36pm UTC](https://discourse.processing.org/t/organising-a-large-a-v-performance-sketch-should-i-make-classes-memory-management/39943/6 "2022-12-15T16:36:57Z")

</div>

hi sableRaph,

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

Best wishes and Nadolig Llawen :-))
