Created
November 6, 2012 06:29
-
-
Save macklinu/4022984 to your computer and use it in GitHub Desktop.
MusicTimeline library issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MusicObject { | |
AudioPlayer song; | |
AudioMetaData meta; | |
String artist; | |
String title; | |
String year; | |
String info; | |
PImage albumArt; | |
String finalImgLoc; | |
String tempImgLoc; | |
String songFile; | |
float trackLength; | |
int roundAmt; | |
float xPos, yPos; | |
boolean hasSong; | |
PFont StagBook, StagBold, StagSans; | |
MusicObject(String s) { | |
// Error in the line below | |
// NullPointerException | |
// The string I'm passing into it is valid, as I've printed it out and seen that it's pulling it correctly from the data source. | |
song = minim.loadFile(s); | |
trackLength = song.getMetaData().length(); | |
StagBook = loadFont("StagBook.vlw"); | |
StagBold = loadFont("StagBold.vlw"); | |
StagSans = loadFont("StagSans.vlw"); | |
roundAmt = 20; | |
tempImgLoc = "img/_na.jpg"; | |
} | |
void setArtist(String s) { | |
artist = s; | |
} | |
void setTitle(String s) { | |
title = s; | |
} | |
void setYear(String s) { | |
year = s; | |
} | |
void setInfo(String s) { | |
info = s; | |
} | |
void setAlbumArt(String imgName) { | |
if (imgName.length() > 0) { | |
finalImgLoc = "img/" + imgName; | |
} | |
else { | |
finalImgLoc = tempImgLoc; | |
} | |
PImage tempImg = loadImage(finalImgLoc); | |
albumArt = roundImageCorners(tempImg, roundAmt); | |
} | |
void setSongFile(String s) { | |
if (s.length() > 0) hasSong = true; | |
else hasSong = false; | |
songFile = "/mp3/" + s; | |
} | |
void setTrackLength(float f) { | |
trackLength = f; | |
} | |
// ======================= | |
String getArtist() { | |
return artist; | |
} | |
String getTitle() { | |
return title; | |
} | |
String getYear() { | |
return year; | |
} | |
String getAlbumArt() { | |
return finalImgLoc; | |
} | |
String getInfo() { | |
return info; | |
} | |
String getSongFile() { | |
return songFile; | |
} | |
PImage displayAlbumArt() { | |
return albumArt; | |
} | |
boolean hasSong() { | |
return hasSong; | |
} | |
float getTrackLength() { | |
return trackLength; | |
} | |
// ======================= | |
void drawPopUp() { | |
noStroke(); | |
fill(240); | |
rect(width/2, height/2, 400, 175, 10); | |
image(albumArt, width/2 - 100, height/2, 150, 150); | |
fill(0); | |
textFont(StagBold, 14); | |
text(artist, width/2, height/2 - 70); | |
textFont(StagBook, 12); | |
text('"' + title + '"', width/2, height/2 - 55); | |
text(year, width/2, height/2 - 40); | |
textAlign(LEFT); | |
text(info, width/2 + 100, height/2 + 160, width/2 - 200, height/2 - 20); | |
} | |
// ======================= | |
// borrowed from http://processing.org/discourse/beta/num_1201879926.html | |
private PImage roundImageCorners(PImage img, int radius) { | |
PImage rounded = createImage(img.height, img.width, ARGB); | |
for (int i=0; i<img.width; i++) { | |
for (int j=0; j<img.height; j++) { | |
float d; | |
if (i < radius && j < radius ) | |
d = dist(i, j, radius, radius); | |
else if (i > img.width - radius - 1 && j < radius ) | |
d = dist(i+1, j, img.width-radius, radius); | |
else if ( i<radius && j>img.height-radius-1 ) | |
d = dist(i, j+1, radius, img.height-radius); | |
else if ( i>img.width-radius-1 && j>img.height-radius-1 ) | |
d = dist(i+1, j+1, img.width-radius, img.height-radius); | |
else | |
d = 0; | |
color pixel = img.pixels[i + img.width*j]; | |
float opacity = constrain(255*(1+radius-d), 0, 255); | |
opacity = min( alpha(pixel), opacity ); // preserve the transparency of the original image. | |
rounded.pixels[i + img.width*j] = color( red(pixel), green(pixel), blue(pixel), opacity ); | |
} | |
} | |
return rounded; | |
} | |
/* | |
void loadSong(String s) { | |
song = minim.loadFile(s); | |
trackLength = song.getMetaData().length(); | |
} | |
*/ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using Processing 2.0b6 | |
// Some functions (namely rect()) won't work in Processing 1.5.1 | |
import ddf.minim.*; | |
import ddf.minim.signals.*; | |
import ddf.minim.analysis.*; | |
import ddf.minim.effects.*; | |
String myFile = "/Users/macklinu/git/MusicTimeline/data/list.csv"; | |
Table Data = new Table(myFile, "|"); | |
int rowCount = Data.getRowCount(); | |
MusicObject[] MO = new MusicObject[rowCount]; | |
Minim minim; | |
boolean play = true; | |
int a = 24; | |
void setup() { | |
Minim minim = new Minim(this); | |
for (int i = 0; i < MO.length; i++) { | |
MO[i] = new MusicObject("/Users/macklinu/git/MusicTimeline/data/mp3/" + Data.getString(i, 5)); | |
} | |
for (int i = 1; i < rowCount; i++) { | |
MO[i].setArtist(Data.getString(i, 0)); | |
MO[i].setTitle(Data.getString(i, 1)); | |
MO[i].setYear(Data.getString(i, 2)); | |
MO[i].setInfo(Data.getString(i, 3)); | |
MO[i].setAlbumArt(Data.getString(i, 4)); | |
MO[i].setSongFile(Data.getString(i, 5)); | |
} | |
size(800, 800); | |
smooth(4); | |
background(0); | |
rectMode(CENTER); | |
imageMode(CENTER); | |
ellipseMode(CENTER); | |
} | |
void draw() { | |
MO[a].drawPopUp(); | |
} | |
void keyPressed() { | |
if (key == 'a') { | |
noStroke(); | |
fill(240, 240, 240, 220); | |
ellipse(width/2 - 100, height/2, 60, 60); | |
fill(0, 0, 0, 180); | |
triangle(width/2 - 108, height/2 -15, width/2 - 108, height/2 + 15, width/2 - 85, height/2); | |
a = 20; | |
} | |
if (key == 's') { | |
stroke(200); | |
strokeWeight(1); | |
fill(230, 230, 230, 220); | |
ellipse(width/2 - 100, height/2, 60, 60); | |
noStroke(); | |
fill(0, 0, 0, 180); | |
rect(width/2 - 100, height/2, 25, 25); | |
a = 10; | |
} | |
if (key == 'd') { | |
noStroke(); | |
fill(240, 240, 240, 220); | |
ellipse(width/2 - 100, height/2, 60, 60); | |
fill(0, 0, 0, 180); | |
rect(width/2 - 100, height/2, 25, 25, 0); | |
a = 14; | |
} | |
} | |
/* | |
void stop() { | |
// the AudioPlayer you got from Minim.loadFile() | |
song.close(); | |
// the AudioInput you got from Minim.getLineIn() | |
minim.stop(); | |
// this calls the stop method that | |
// you are overriding by defining your own | |
// it must be called so that your application | |
// can do all the cleanup it would normally do | |
super.stop(); | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Table { | |
int rowCount; | |
String[][] data; | |
Table(String filename, String delim) { | |
String[] rows = loadStrings(filename); | |
data = new String[rows.length][]; | |
for (int i = 0; i < rows.length; i++) { | |
if (trim(rows[i]).length() == 0) { | |
continue; // skip empty rows | |
} | |
if (rows[i].startsWith("#")) { | |
continue; // skip comment lines | |
} | |
// split the row on the tabs | |
data[rowCount++] = split(rows[i], delim); | |
} | |
// resize the 'data' array as necessary | |
data = (String[][]) subset(data, 0, rowCount); | |
} | |
int getRowCount() { | |
return rowCount; | |
} | |
// find a row by its name, returns -1 if no row found | |
int getRowIndex(String name) { | |
for (int i = 0; i < rowCount; i++) { | |
if (data[i][0].equals(name)) { | |
return i; | |
} | |
} | |
println("No row named '" + name + "' was found"); | |
return -1; | |
} | |
String getRowName(int row) { | |
return getString(row, 0); | |
} | |
String getString(int rowIndex, int column) { | |
return data[rowIndex][column]; | |
} | |
String getString(String rowName, int column) { | |
return getString(getRowIndex(rowName), column); | |
} | |
int getInt(String rowName, int column) { | |
return parseInt(getString(rowName, column)); | |
} | |
int getInt(int rowIndex, int column) { | |
return parseInt(getString(rowIndex, column)); | |
} | |
float getFloat(String rowName, int column) { | |
return parseFloat(getString(rowName, column)); | |
} | |
float getFloat(int rowIndex, int column) { | |
return parseFloat(getString(rowIndex, column)); | |
} | |
void setRowName(int row, String what) { | |
data[row][0] = what; | |
} | |
void setString(int rowIndex, int column, String what) { | |
data[rowIndex][column] = what; | |
} | |
void setString(String rowName, int column, String what) { | |
int rowIndex = getRowIndex(rowName); | |
data[rowIndex][column] = what; | |
} | |
void setInt(int rowIndex, int column, int what) { | |
data[rowIndex][column] = str(what); | |
} | |
void setInt(String rowName, int column, int what) { | |
int rowIndex = getRowIndex(rowName); | |
data[rowIndex][column] = str(what); | |
} | |
void setFloat(int rowIndex, int column, float what) { | |
data[rowIndex][column] = str(what); | |
} | |
void setFloat(String rowName, int column, float what) { | |
int rowIndex = getRowIndex(rowName); | |
data[rowIndex][column] = str(what); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment