Loading...
Logo
Processing Forum
drowned's Profile
3 Posts
2 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    I'm currently working on a larger project, but I'll break down my question into a simple example

    I have a 2-dimensional array of integers that stores data on what volume level to play at certain points in time.  One of the dimensions stores a time in milliseconds, and the other dimension stores the volume level.

    I loop through this array, checking when each change in volume should occur.

    All of that is done.


    My goal is to visualize this in a horizontal timeline, similar to a channel on a sequencer like this:


    I'd display the volume at each point in time. I'd also want to be able to click on the points so I could trigger some other code I have to change the value. 


    I know it would be too large (horizontally) for my screen, so I'd have to come up with a scroll bar and maybe some way to pre-buffer the data.

    Has anyone done anything like this and have any tips?

    I'm trying to nest a class within a class.  The reason is I need to store a series of pieces of information (an integer, and a boolean value) multiple times within the main class. In C++ i'd use a struct, but it doesn't seem that java has the same option.

    I've been getting a Null Pointer Exception error and searched all over the internet about how to handle nested classes when we need  multiple instances of the inside one  , but didn't have much luck. Line 25 is where the error is occuring.  I tried multiple versions, and this is just the latest one that I have after stumbling through different examples.

    I may be doing this all wrong. Is there a better way I can store pairs of variables (such as a milliseconds as an integer, and a true/false value as a boolean) and easily iterate through them? I originally used 2 arrays (one for time, and one for the true/false value) but it didn't work as well as I'd like. When I look through I want to get the integer value from smallest to largest, regardless of whether it has a true or false value. I'm thinking I could also try encoding the boolean value into a single integer along with the other integer value but that seems like too much of a hack.

    (On a side note, I know that I'll need to have code to expand the number of instances. I haven't researched that part yet since this part has me stumped.

    Thanks



    1. class LedChannel {
    2.   private int pin;
    3.   private boolean alreadycounted;
    4.   private int lastused;
    5.   private Timeline[] timing;
    6.    
    7.   public LedChannel(int xpin) {
    8.     this.pin = xpin;
    9.     this.alreadycounted = false; 
    10.     this.lastused = 0;
    11.     Timeline[] timing = new Timeline[1];
    12.       timing[0] = new Timeline();

    13.   }
    14.   
    15.   public class Timeline() {
    16.     public int currtime;
    17.     public boolean ledstatus;
    18.   } 
    19.   
    20.  public void addvalue(int tmptime, boolean tmpstatus ) {
    21.     // The line below this errors with a  NULL POINTER EXCEPTION
    22.     timing[lastused].currtime = tmptime;
    23.     timing[lastused].ledstatus = tmpstatus;
    24.     lastused++;
    25.   }
    26. }  
    27.     
    28.