Creating multiple arrays from a txt file

edited August 2017 in Library Questions

I'm currently trying to create a visual diagram of solar winds within processing, but I'm struggling on trying to structure it and I need help.

Using http://services.swpc.noaa.gov/text/ace-swepam.txt I need to collect proton density, bulk speed and ion temperature and create a visual diagram which I will get into once I've collected all 120 points of data (1 per minute over the course of 2 hours)

I've worked with txt files before because they're easier to determine and separate different values, but I would still struggle with removing certain values from a row of multiple values.

This was my original idea on how to do it, but doing it this way would require copying and pasting this 120 times and adjusting it along the way.

I want to do what I've done, but using i+ 120 times to get everything stored in a single array but I have no idea how.

«1

Answers

  • edited August 2017 Answer ✓

    The best way would be to create a class Record which holds all the data for a single line in an accessible format.

    This code reads the data from the file and creates an array of Records, one element for each line of data.

    If you run the following sketch it should become apparent how it works but if you need anything explaining just ask.

    Record[] records;
    
    void setup() {
      String[] rawData = loadStrings("http://" + "services.swpc.noaa.gov/text/ace-swepam.txt");
      records = getRecordsFromRawData(rawData);
    }
    
    void showSomeData() {
      for (Record r : records) {
        println(r.density, r.speed, r.temperature);
      }
    }
    
    Record[] getRecordsFromRawData(String[] data) {
      ArrayList<Record> r = new ArrayList<Record>();
      for (String line : data) {
        char c = line.charAt(0);
        // data line starts with a number
        if (c >= '0' && c <= '9') {
          r.add(new Record(line));
        }
      }
      return r.toArray(new Record[r.size()]);
    }
    
    class Record {
      int year, month, day;
      int hour, minute;
      int julianDay;
      int secsOfDay;
      int s;
      float density, speed, temperature;
    
      public Record(String lineOfData) {
        // Split on whitespace
        String[] items = lineOfData.split("\\s+");
        year = int(items[0]);
        month = int(items[1]);
        day = int(items[2]);
        int hhmm = int(items[3]);
        hour = hhmm & 100;
        minute = hhmm / 100;
        julianDay = int(items[4]);
        secsOfDay = int(items[5]);
        s = int(items[6]);
        density = float(items[7]);
        speed = float(items[8]);
        temperature = float(items[9]);
      }
    }
    
  • edited August 2017

    So how exactly would I be able to use the speed, density and temperature to create a visual? For example to determine the shape and size of a triangle? I mean, in terms of taking the data out of the array you've made rather than "how do I make a triangle".

  • You last comment makes no sense.

    What do you want to visualise?

    Where does a triangle come into the visualisation?

  • Well, considering there are three different values I want to present for each minute, a triangle was the first thing that came to mind. Either that or something else that I can do for each minute of the data.

  • Anyway, point being; How do I take data out of the array you've made?

  • See line 10 for that

    Call showSomeData from draw()

  • edited August 2017

    Since this is data over time think of it as a graph :

    • X-axis is time (120 steps)

    • And on y-axis use three colors (one color for density, one for speed etc.), make ellipses for each value (connect with lines if you like, but that's controversial maybe)

  • you need to do some scaling to get all data fitting into the screen ;-)

    Record[] records;
    
    void setup() {
      size(1100, 990); 
    
      String[] rawData = loadStrings("http://" + "services.swpc.noaa.gov/text/ace-swepam.txt");
      records = getRecordsFromRawData(rawData);
    }
    
    void draw() {
      showSomeData();
    }
    
    // -----------------------------------------------
    
    void showSomeData() {
      int i=0; 
      for (Record r : records) {
        println(r.density, r.speed, r.temperature);
        fill(255, 0, 0); // red 
        ellipse(3 + i*3, r.speed, 4, 4);
        fill(255, 0, 250); // 
        ellipse(3 + i*3, r.temperature * .01, 4, 4);
        i+=3; // increase by 3
      }
      noLoop();
    }
    
    Record[] getRecordsFromRawData(String[] data) {
      ArrayList<Record> r = new ArrayList<Record>();
      for (String line : data) {
        char c = line.charAt(0);
        // data line starts with a number
        if (c >= '0' && c <= '9') {
          r.add(new Record(line));
        }
      }
      return r.toArray(new Record[r.size()]);
    }
    
    // ==================================================================
    
    class Record {
    
      int year, month, day;
      int hour, minute;
      int julianDay;
      int secsOfDay;
      int s;
      float density, speed, temperature;
    
      // constructor
      public Record(String lineOfData) {
        // Split on whitespace
        String[] items = lineOfData.split("\\s+");
        year = int(items[0]);
        month = int(items[1]);
        day = int(items[2]);
        int hhmm = int(items[3]);
        hour = hhmm & 100;
        minute = hhmm / 100;
        julianDay = int(items[4]);
        secsOfDay = int(items[5]);
        s = int(items[6]);
        density = float(items[7]);
        speed = float(items[8]);
        temperature = float(items[9]);
      }
    } // class
    //
    
  • So, how would I go about to show off the value of each data set? As the way it's presented is impossible to read and compare the data in terms of what the values actually are as proton density is usually between the values of 0-2, but the bulk speeds are 300-400.

  • edited August 2017

    Maybe I should use three different graphs so it's easier to value each set of data as individual values? And in terms of actually making it seem more presentable, how would I go about to connect each form of data with a line so it's easier to tell that "this data is at the same time of this data".

  • Just use 3 times the command line() with x values always the same and y values of the data (to connect data recorded at the same time vertically)

  • edited August 2017

    But I'm not sure how to do that because of all the multipliers being added in order to make the graph more presentable in terms of comparing data.

  • edited August 2017

    I got it;

    Jesus, thanks a LOT for the help.

  • edited August 2017

  • edited August 2017

    how do I remove singular irregular data?

    (see speed value on the far right for example of irregular data)

  • Also the 10th value seems to be non Existent

    You can check with if if they are outside screen

  • is there anyway to create audio feedback based on the data collected?

  • Sure.

    Look at the section libraries, either library sound or minim

  • Is it not on the library page? It is also a library.

    Then google it

  • @CentricArts -- The minim sound library (available in PDE Contributions Manager), and recent minim discussions:

  • edited August 2017

    So how exactly would I be able to use the data I've collected and execute 3 different sounds that effect the pitch depending on the data in the table.

    So if I hover over a value, it would play 3 different sounds. One for speed, density and temperature which are effected in pitch based on a multiplier which would be the data itself.

    But how would I go about reading mouse data and array data to execute that is by using void mousepressed() would require me to out of the records[], how would I got about collecting and using the data?

  • This next post talks about how to get the data that is under the mouse pointer: https://forum.processing.org/two/discussion/23097/how-can-i-determine-which-spectrum-is-generated-from-which-file-on-mouseclick#latest

    For data into audio, check: http://code.compartmental.net/minim/javadoc/ddf/minim/AudioOutput.html

    You can populate the buffer and then play it. You can see more examples from previous posts: https://forum.processing.org/two/search?Search=audiooutput

    Kf

  • edited August 2017

    I don't need to collect data under the mouse pointer, I already have the data stored in records[]. I've already made if statements to read if the mouse is in a certain area, depending on the area will depend the sound it plays back.

    My question is, considering I've created the code based on a record[] based format, how exactly do I collect the data to take it out and put it in mousepressed? I've always used arrays to solve these problems but it's difficult considering the data I have is only usable in records[]

    I was thinking of an array that stores whatever is in the r.speed[], r.density[] and r.temp[] so I can use it outside of the records, but I'm not really sure on how I would do that.

  • edited August 2017

    tldr; How do I use r.speed[] outside of showSomeData();

  • edited August 2017 Answer ✓

    Explanation

    normally you have e.g. float [] listOfFloats;

    it's an array of float. An expression like listOfFloats[12] gives you a number.

    here you now have Record[] records; which is an array of Record:

    • an array of the class Record.

    Other than float, each Record has a couple of items defined in the class Record: float density, speed, temperature etc.

    (there is a tutorial on objects you might want to read:

    https://www.processing.org/tutorials/objects/ )

    To access one Record in the array use the dot . :

    records[12].speed; 
    records[12].density;
    etc. 
    

    So instead of having multiple parallel arrays speed[] and density[] etc., we have only on array and in each slot of it there is one speed, one density etc. Record.

    How do I use r.speed[] outside of showSomeData()

    r.speed[] is wrong it's just r.speed

    The r stems from the for-loop for (Record r : records) {

    (which in turn is a short version of the classical for-loop)

    it says: copy each item of the array records into r (being of type Record) one after the other, so it loops over each Record in records.

    Classic form would be

    for(int i=0; i<records.length; i++)  {
         println(records[i].speed); 
    }
    

    So your answer is: you can say records[12].speed or records[i].speed anywhere in your code. Not only in showSomeData()

    Chrisir ;-)

  • Oh fuck, that's easier than I thought. I understood how record[] worked but I didn't understand how to use it other than in the showSomeData(); as it directly refers to r.records when r. isn't a thing anywhere else. It's just an alternative to addressing something in a section of code that's designed to deal with this kinda stuff as a mainstream.

    But yeah, records[i].speed was all I wanted to know. Thanks!

  • edited August 2017

    Is there any other way to do something like this 120 times more efficiently? (ignore the L value, I was trying to sort out a loop to check this for me but it didn't work)

    • I'm still not sure on how to change the pitch of sounds
  • You could just play the data from left to right automatically once the mouse is pressed

    I am not sure what your goal is.

    Do you want a program where you click on one column with the mouse and then the three data points of it are played one after the other?

    Then you need to for loop over the columns and check if mouse position is inside.

    Look deeper into minim - or sound library.

    You can just tell it to play a tone with a frequency

  • edited August 2017

    it reads the data of the mouse and depending on the values of temp and density, for that column it will play different pitches in sound based on multipliers of the data its presenting in the table. The time between the two notes are then dependent on the speed of the wind.

    The max speed of speed is around 800, so 800-records[sl].speed. [sl] is me trying to create a loop to detect the horizontal value in a database as the grid but that doesn't work because mousepressed() is event driven information and without information it can't do shit.

    Which is the thing I'm struggling with to prevent me copying and pasting the same code 120 times.

  • edited August 2017

    Ok, i guess that's just some basic stuff you will learn easily

    In mousePressed make a for loop similar to the one you have for the output in showSomeData

    Here you use the same x value and say if(mouseX>x-3&&mouseX<x+3) {......

    then just use the int i of the for loop to access the array records[i].speed and trigger the note / tone / sound with that pitch --- do the calculations on the fly in the if-clause (which is nested in the for loop)

  • I think I got it! I just have to change the pitch. How do I change the pitch of a imported .wav file?

  • I have no idea

    As said I think you don't want a wave but rather a note / tone

  • I've tried to look up this stuff but it's really complicate as it centers around how to generate sound rather than how to use it based on other aspects like multipliers. I just need a way how to generate a sound and change it through pitch using minim. no idea how.

  • Maybe look at sound library (name is sound) or minim examples/ reference

    I can look into it tonight

  • /**
     * This sketch demonstrates how to create synthesized sound with Minim 
     * using an AudioOutput and an Oscil. An Oscil is a UGen object, 
     * one of many different types included with Minim. For many more examples 
     * of UGens included with Minim, have a look in the Synthesis 
     * folder of the Minim examples.
     */
    
    import ddf.minim.*;
    import ddf.minim.ugens.*;
    
    Minim       minim;
    AudioOutput out;
    Oscil       wave;
    
    float[] notes ;
    
    void setup()
    {
      size(512, 200, P3D);
    
      notes = new float[8] ; // create the array to hold the note frequencies
      notes[0] = 261.63 ;
      notes[1] = 293.67 ;
      notes[2] = 329.63 ;
      notes[3] = 349.23 ;
      notes[4] = 391.99 ;
      notes[5] = 440 ;
      notes[6] = 493.88 ;
      notes[7] = 523.25 ;
    
      minim = new Minim(this);
    
      // use the getLineOut method of the Minim object to get an AudioOutput object
      out = minim.getLineOut();
    }
    
    void draw()
    {
      background(0);
      stroke(255);
    
      // draw the waveforms
      for (int i = 0; i < out.bufferSize() - 1; i++)
      {
        line( i, 50 + out.left.get(i)*50, i+1, 50 + out.left.get(i+1)*50 );
        line( i, 150 + out.right.get(i)*50, i+1, 150 + out.right.get(i+1)*50 );
      }
    }
    
    void keyPressed() {
      //wave.reset();
      switch(key) {
      case ' ':
        if (wave!=null&&out!=null)
          wave.unpatch(out);
        break;
    
      default:
        // all other keys 
        int asc1 = int(key); 
        println (asc1);
        if (asc1>='a'&&asc1<='h') {
          if (wave!=null&&out!=null) {
            wave.unpatch(out);
          } // if 
          //wave.unpatch(out);
          // create a sine wave Oscil, set to 440 Hz, at 0.5 amplitude
          if ((asc1-97) < 8)
            wave = new Oscil( notes[asc1-97], 0.5f, Waves.SINE );
          // patch the Oscil to the output
          wave.patch( out );
        } // if 
        break;
      }
    }
    
    void stop()
    {
      minim.stop();
      super.stop() ;
    }
    //
    
  • these codes are all not by me

    here is another one:

    import java.util.Arrays; 
    import javax.sound.midi.*; 
    
    MusicBox musicbox;
    
    int[] blackRect = {1, 1, 0, 1, 1, 1, 0, 1};
    
    String[] blackName = {"ais", "cis", "dis", "eis", "fis", "gis", "b", "cis"};
    String[] blackNote = {"ais", "cis", "dis", "eis", "fis", "gis", "b", "cis"};
    
    String[] whiteName = {"a", "c", "d", "e", "f", "g", "h", "c", "d", "e"};
    
    // this doesn't make much sense: 0 = ? But color(0) is ok.
    color[] couleur = {color(0), color(0), 0, color(0), color(0), color(0), 0, color(0)};
    
    ArrayList<Key> keys = new ArrayList();
    
    // ---------------------------------------------------
    
    void setup() {
    
      size(1280, 750);
    
      musicbox=new MusicBox();
      musicbox.initialize();
    
      int width_white = 38; // width 1
      int width_black = 19; // width 2
    
      // defining all keys  
    
      // white Rects
      for (int i = 0; i < 9; i++) { 
        // fill(128);
        // stroke(0);
        keys.add ( 
          new Key (width/2+30-(i*width_white), 110+111, width_white, 186, 
          whiteName[i], "C-Note", 
          color(255), color(0), i+44));
      }//for
    
      //black Rects
      for (int x = 0; x < 8; x++) {
        // fill(couleur[x]);
        // -1 is for noStroke();
        if (blackRect[x] == 1)
          keys.add (
            new Key (width/2+30-(2 * x * width_black)-10, 110+111, width_black, 140, 
            blackName[x], blackNote[x]+"-Note", 
            couleur[x], 0, x+55));
      }//for 
      //
    }// func 
    
    void mousePressed() {
      // all keys
      for (Key k : keys) {
    
        if (k.over(mouseX, mouseY)) {
          // 
          println(k.name
            +" -> "
            +k.note);
          musicbox.playNote(k.noteNumber, 1000);
          return;
        }//if
      }//for
    }//func 
    
    void draw() {
      background(0);
    
      //translate(width/2, 111);
    
      stroke(111);
      noFill();
    
      // all keys
      for (Key k : keys) {
        k.display();
      }
    }
    
    void keyPressed() {
      // not in use
    }
    
    // ===========================================
    // the class - a blueprint for one key 
    
    class Key {
    
      float x;
      float y; 
    
      float w; 
      float h; 
    
      String name;
      String note; 
      int noteNumber=55; 
    
      color colFill;
      color colStroke; 
      color colKey; 
    
      PVector translatePVector;
    
      //constr
      Key(float x_, float y_, 
        float w_, float h_, 
        String name_, 
        String note_, 
        color colFill_, 
        color colStroke_, 
        int noteNumber_ ) {
    
        x=x_;
        y=y_;
    
        w=w_;
        h=h_;
    
        name=name_;
        note=note_;
    
        colFill = colFill_;
        colStroke = colStroke_; 
    
        noteNumber=noteNumber_;
        //
      }//constr
    
      void display() {
    
        fill(colFill);
        if (colStroke==-1) 
          noStroke(); 
        else
          stroke(colStroke);
        rect(x, y, w, h);
      }//method
    
      boolean over(float x1, float y1) {
        return x1>x&&
          y1>y&&
          x1<x+w&&
          y1<y+h;
      }// method 
      //
    }
    
    // =============================================================
    
    public class MusicBox { 
    
      Synthesizer synthesizer; 
      MidiChannel[] channels; 
    
      boolean noSound = false;
    
      void initialize() { 
        try { 
          if (!noSound) { 
            synthesizer = MidiSystem.getSynthesizer(); 
            synthesizer.open();
    
            channels = synthesizer.getChannels();
    
            Instrument[] instr = synthesizer.getDefaultSoundbank()
              .getInstruments();
            synthesizer.loadInstrument(instr[0]);
            System.out.println(channels.length);
          }
        }
        catch (Exception ex) {
          System.out.println("Could not load the MIDI synthesizer.");
        }
      }
    
      void cleanUp() { 
        if (synthesizer != null) synthesizer.close();
      }
    
      public void playNote( final int note, 
        final int milliseconds) { 
        System.out.println("");
        Thread t = new Thread() {
          public void run() {
            try {
              if (!noSound && channels != null && channels.length > 0) {
                channels[0].noteOn(note, 120);
                sleep(milliseconds);
                channels[0].noteOff(note);
              }
            } 
            catch (Exception ex) {
              System.out.println("ERROR: " + ex);
            }
          }
        };
        t.start();
      }
    
      public void playChord(int note1, int note2, int note3, 
        int milliseconds) { 
        playChord(new int[] {note1, note2, note3}, milliseconds);
      }
    
      public void playChord(final int[] notes, 
        final int milliseconds) { 
        System.out.println("");
    
        Thread t = new Thread() {
          public void run() {
            try {
              if (!noSound && channels != null && channels.length > 0) {
                int channel = 0;
                for (int n : notes) {
                  channels[channel++].noteOn(n, 120);
                }
                sleep(milliseconds);
                for (channel = 0; channel < notes.length; channel++) {
                  channels[channel].noteOff(notes[channel]);
                }
              }
            }
            catch (Exception ex) {
              System.out.println("ERROR:" + ex);
            }
          }
        };
        t.start();
      }
    
      public void playScale(int note1, int note2, int note3, int note4, int note5, int note6, int note7, int note8, 
        int milliseconds) { 
        playScale(new int[] {note1, note2, note3, note4, note5, note6, note7, note8}, milliseconds);
      }
    
      public void playScale(final int[] notes, final int milliseconds) { 
    
        Thread t = new Thread() { 
          public void run() { 
            try { 
              if (!noSound && channels != null && channels.length > 0) { 
                for (int n : notes) { 
                  channels[0].noteOn(n, 120); 
                  sleep(milliseconds); 
                  channels[0].noteOff(n);
                }
              }
            } 
            catch (Exception ex) { 
              System.out.println("ERROR:" + ex);
            }
          }
        };
        t.start();
      }
    
      private void sleep(int length) { 
        try { 
          Thread.sleep(length);
        } 
        catch (Exception ex) {
        }
      }
    }// class 
    //
    
  • edited August 2017

    Jesus Christ. I have no idea what half of this code is for and how to even use it in the slightest in my own.

  • Now, these are 2 sketches.

    Try the first one- it's pretty straight forward

  • edited August 2017

    I've tried using the first one, but I can't even get an output using the values in my data

    I'm probably missing something obvious but I'm not sure what it is.

  • I am not at home today maybe somebody can jump in

  • edited August 2017

    this has to be completed by tomorrow morning, so I doubt it.

    However, I did come up with an alternate solution towards my problem but it isn't as well implemented as actually having pitch shifts as it's easier to tell the difference between different values.

  • edited August 2017

    But if nothing arises I thank everyone for giving me a hand with doing this

  • Which time zone?

    Post your entire code as text

  • edited August 2017
      float P = 0;
      float A = 0;
      float spe[];
      float den[];
      float temp[];
      int DC = 0;
      import ddf.minim.* ;
      import ddf.minim.signals.* ;
      import ddf.minim.effects.* ;
      import java.util.Arrays; 
      import javax.sound.midi.*; 
      Minim minim;
      AudioPlayer player;
    //======================================
                   //SETUP
    //======================================
    void setup() {
      println("Setup");
      size(1887, 1000); 
      println("Loading Data");
    //======================================
                  //SOUND DATA
    //======================================
      minim = new Minim(this);
      player = minim.loadFile("106821.wav");
    //======================================
                  //VISUAL DATA
    //====================================== 
      println("");
    //======================================
      String[] rawData = loadStrings("http://" + "services.swpc.noaa.gov/text/ace-swepam.txt"); //data
      records = getRecordsFromRawData(rawData);
    }
    //======================================
    Record[] records;
    void draw() {
    //======================================
      showSomeData();
    }
    void showSomeData() {
      float H = 100; //GRID VAR
      float W = 1920; //LENGTH VAR
      println("Data Loaded");
    //======================================
                   // DEBUG
    //======================================
      println("Debug;");
    //    float A = r.temperature/10000;
    //    float B = r.speed/100;
    //    float C = r.density;
    //    println(A);
    //    println(B);
    //    println(C);
    //======================================
        println("Debug End");
        println("Table Start");
    //======================================
                   //grid
    //====================================== 
        fill(175, 175, 175); //Gray
        stroke(175, 175, 175); //Gray outline
        rect(32*3,0,0,1920); //side
    //======================================
              //HOR
    //======================================
        stroke(170, 170, 170);
        rect(101+(15*3),0,0,W);
        rect(101+(15*7),0,0,W);
        rect(101+(15*11),0,0,W);
        rect(101+(15*15),0,0,W);
        rect(101+(15*19),0,0,W);
        rect(101+(15*23),0,0,W);
        rect(101+(15*27),0,0,W);
        rect(101+(15*31),0,0,W);
        rect(101+(15*35),0,0,W);
        rect(101+(15*39),0,0,W);
        rect(101+(15*43),0,0,W);
        rect(101+(15*47),0,0,W);
        rect(101+(15*51),0,0,W);
        rect(101+(15*55),0,0,W);
        rect(101+(15*59),0,0,W);
        rect(101+(15*63),0,0,W);
        rect(101+(15*67),0,0,W);
        rect(101+(15*71),0,0,W);
        rect(101+(15*75),0,0,W);
        rect(101+(15*79),0,0,W);
        rect(101+(15*83),0,0,W);
        rect(101+(15*87),0,0,W);
        rect(101+(15*91),0,0,W);
        rect(101+(15*95),0,0,W);
        rect(101+(15*99),0,0,W);
        rect(101+(15*103),0,0,W);
        rect(101+(15*107),0,0,W);
        rect(101+(15*111),0,0,W);
        rect(101+(15*115),0,0,W);
        rect(101+(15*119),0,0,W);
        rect(101+(15*121),0,0,W);
    //======================================
              //VER
    //======================================
        rect(32*3,H*1,W,0);
        rect(32*3,H*2,W,0);
        rect(32*3,H*3,W,0);
        rect(32*3,H*4,W,0);
        rect(32*3,H*5,W,0);
        rect(32*3,H*6,W,0);
        rect(32*3,H*7,W,0);
        rect(32*3,H*8,W,0);
        rect(32*3,H*9,W,0);
    //======================================
        rect(32*3,H*10,W,0);
        rect(32*3,H*11,W,0);
        rect(32*3,H*12,W,0);
        rect(32*3,H*13,W,0);
        rect(32*3,H*14,W,0);
        rect(32*3,H*15,W,0);
        rect(32*3,H*16,W,0);
        rect(32*3,H*17,W,0);
        rect(32*3,H*18,W,0);
        rect(32*3,H*19,W,0);
        rect(32*3,H*20,W,0); 
        println("");
        println("Done");
    //======================================
               //Lines Default
    //======================================
      int i=32; //Data offset
        println("");
        println("Loop Start");
      for (Record r : records) {
        println(r.density, r.speed, r.temperature, r.time); //Debug Storage
    //======================================
        // Bottom Half
        if(r.temperature > 0){ //filter 1
          if(r.speed > 0){ //filter 2
            stroke(255, 0, 255);
            line(i*3+5,r.temperature * .001 + 500,i*3+5,r.speed*1-100); //Line Calc
          }
        }
    //======================================
            // Top Half
        if(r.density > 0){ //filter 1
          if(r.speed > 0){ //filter 2
            stroke(0, 255, 255);
            line(i*3+5,r.density * 100 + 100,i*3+5,r.speed*1-100); //Line Calc
          }
        }
    //======================================
               //Time Overlay
    //======================================
        if(P < 3){
          P = P + 1;
        } else {
          fill(100,100,100);
          text(r.time,(i*3)+8,994);
          P = 0;
        }   
    //======================================
               //Line Corrections
    //======================================
        // Overlay 1A
        if((r.density * 100 + 100) > (r.temperature * .001 + 400)){
            stroke(255, 0, 255);
            line(i*3+5,r.speed*1-100,i*3+5,r.temperature * .001 + 500); //Line Calc
            println("< H1 CY >");
        }
        // Overlay 1B
            if((r.temperature * .001 + 500) > (r.density * 100 + 100)){
            stroke(0, 255, 255);
            line(i*3+5,r.speed*1-100,i*3+5,r.density * 100 + 100); //Line Calc
            println("< H1 MA >");
        }
        // Overlay 2
        if((r.temperature * .001 + 500) < (r.speed*1-100)){
            stroke(255, 0, 255);
            line(i*3+5,r.speed*1-100,i*3+5,r.temperature * .001 + 500); //Line Calc
            println("< H2 CY >");
        }
        line(i*3+5,900,i*3+5,900); //seperator
    
        float cor = r.temperature;
        if(cor < 0){
          stroke(255, 100, 100);
          fill(255, 100, 100);
          rect(i*3,0,10,980);
        }
    //======================================
                 //CALCULATIONS
    //====================================== 
        if(r.speed > -1){
        fill(100, 100, 100); // white
    //    stroke(100, 100, 100); // white
        stroke(100, 100, 100); // Gray
        ellipse(5 + i*3, (r.speed*1-100), 4, 4); //SPEED
    // filter 
        } else {ellipse(5 + i*3, 400, 4, 4);
        println("Invalid data (SPEED)");} //debug
    //======================================
        if(r.temperature > -1){
        fill(255, 0, 250); // magenta
    //    stroke(255, 0, 250); // magenta
        stroke(100, 100, 100); // Gray
        ellipse(5 + i*3, (r.temperature * .001 + 500), 4, 4); // TEMP
    // filter 
        } else {ellipse(5 + i*3, 400, 4, 4);
        println("Invalid data (TEMP)");} //debug
    
            if(r.temperature < 59000){
        r.temperature = 59000;
      }
    //======================================
        if(r.density > -1){
        fill(0, 255, 255); // cyan
    //    stroke(0, 255, 255); // cyan
        stroke(100, 100, 100); // Gray
        ellipse(5 + i*3, (r.density * 100 + 100), 4, 4); //DESNITY
    // filter 
        } else {ellipse(5 + i*3, 400, 4, 4);
        println("Invalid data (DENSITY)");} //debug
    //======================================
        i+=5; // loop increase
    //====================================== 
                  //OVERLAY
    //====================================== 
        // etc
        fill(150, 150, 150); // gray
        text("+",4,995);
    
        text("h h m m",100,983); //bottom left
        text("T I M E:",100,995);
    //======================================
        stroke(100, 100, 100); // cyan
        fill(100, 100, 100); // black
        text("W I N D  S P E E D  D A T A",4,14); //title
    //======================================
                //SIDEBAR
    //======================================
        text("0 . 0  p / c c",4,128);
        text("1 . 0  p / c c",4,228);
        text("2 . 0  p / c c",4,328);
        text("3 . 0  p / c c",4,428);
        text("4 . 0  p / c c",4,528);
        text("5 . 0  p / c c",4,628);
        text("6 . 0  p / c c",4,728);
        text("7 . 0  p / c c",4,828);
        text("2 0 0  k m / s",4,114);
        text("3 0 0  k m / s",4,214);
        text("4 0 0  k m / s",4,314);
        text("5 0 0  k m / s",4,414);
        text("6 0 0  k m / s",4,514);
        text("2 0 0 0 0 0  k",4,642);
        text("-2 0 0 0 0 k",4,342);
        text("-1 0 0 0 0 k ",4,442);
        text("1 0 0 0 0  k  ",4,542);
        text("7 0 0  k m / s",4,614);
        text("3 0 0 0 0 0  k",4,714);
        text("4 0 0 0 0 0  k",4,814);
        text("5 0 0 0 0 0  k",4,914);
    //======================================
                 //DESNITY
    //====================================== 
        // cyan
        fill(0, 255, 255);  
        stroke(100, 100, 100); // gray outline
        rect(80,118,12,12);
        rect(80,218,12,12);
        rect(80,318,12,12);
        rect(80,418,12,12);
        rect(80,518,12,12);
        rect(80,618,12,12);
        rect(80,718,12,12);
        rect(80,818,12,12);
        //key
        rect(80,956,12,12);
        text("D e n s i t y",12,966);
    //======================================
                  //speed
    //====================================== 
        // gray
        fill(100,100,100); 
        rect(80,104,12,12);
        rect(80,204,12,12);
        rect(80,304,12,12);
        rect(80,404,12,12);
        rect(80,504,12,12);
        rect(80,604,12,12);
        //key
        rect(80,970,12,12);
        text("S p e e d",25,978);
    //======================================
                   //temp
    //====================================== 
        // magenta
        fill(255, 0, 255); 
        rect(80,332,12,12);
        rect(80,432,12,12);
        rect(80,532,12,12);
        rect(80,632,12,12);
        rect(80,704,12,12);
        rect(80,804,12,12);
        rect(80,904,12,12);
        //key
        rect(80,984,12,12);
        text("T e m p ",32,990);
    //======================================
             //Error Count
    //====================================== 
          if(r.speed < -1){
            DC = DC + 1 ;
          }
      }
    //======================================
      noLoop(); // loop end
      println("");
      println("Loop End");
      println("Error Count : ", DC);
      println("");
      println("=====================================");
      println("");
      println("The delay between first and second key is equal to density * speed");
      println("The delay between second and third key is equal to speed * temp");
      println("The longer the delay, the faster the wind, density or temp. ");
      println("");
      println("=============== debug ===============");
    }
    //======================================
               //storage setup A
    //======================================
    Record[] getRecordsFromRawData(String[] data) {
      ArrayList<Record> r = new ArrayList<Record>();
      for (String line : data) { //var
        char c = line.charAt(0); // data line
        if (c >= '0' && c <= '9') {
          r.add(new Record(line));
        }
      }
      return r.toArray(new Record[r.size()]);
    }
    //======================================
                //Storage setup B
    //======================================
    class Record {
      float density, speed, temperature; //var
      int time;
    //======================================
      public Record(String lineOfData) {
        String[] items = lineOfData.split("\\s+");
    //======================================
        density = float(items[7]); //cyan
        speed = float(items[8]); //gray
        temperature = float(items[9]); //magenta
        int hhmm = int(items[3]);
        time = hhmm;
        //println(hhmm);
      }
    }
    //======================================
                //Mouse Storage
    //======================================
    void mousePressed(){
        int X = pmouseX;
        int Y = pmouseY;
    //======================================
        int s = 15;
        int l = 1;
        //println(X);
    //======================================
               //Sound Playback
    //======================================
    for ( Record r : records) {
          if(X >= 99 - 15 + (s*l) && X <= 103 - 15 + (s*l)){
            println("");
            println(r);
    //======================================
            float S = records[l].speed;
            println("Speed : ", S);
            float D = records[l].density;
            println("Density : ", D);
            float T = records[l].temperature;
            println("Temperature : ",T);
    //======================================
    
            int A = (int)S * (int)D;
            int B = (int)T / (int)S + 400;
            println("Debug S * D : ", A);
            println("Debug T / S : ", B);
    //======================================
            if(A < 10000){
              player.rewind();
              player.play();
              delay((int)A);
              player.rewind();
              player.play();
              delay((int)B);
              player.rewind();
              player.play();
            } else {
             println("Invalid data set");
            }
    //======================================
          }
          l = l + 1;
       }
    }
    //======================================
                    //END
    //======================================
    
  • this isn't the final version of the code, but it is the code that I was trying to get pitch tones depending on different values of data when you click.

    The 17th is when the hand in is at 3pm, GMT. But I'm leaving tomorrow afternoon at 12pm so I have to hand in before that time.

  • Did the pitch thing work?

  • edited August 2017

    No, that's why my backup is just three notes with delays based on speed*density and (temp/speed)/100

  • it works fine, but as I said previously, pitching would be easier to differentiate between values easier

Sign In or Register to comment.