id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
7af198da-76fd-4570-a014-cbee763fa4ac | private void gotoImport() {
try {
ImportController importer = (ImportController) replaceSceneContent("ui/fxml/Import.fxml");
importer.setApp(this);
} catch (Exception e) {
// An error occurred
e.printStackTrace();
}
} |
ad734e60-f998-4e66-8598-6196c91bcc6e | public void gotoTabViewer(Tablature t) {
tabs = t;
try {
// Load from path
TabViewerController viewer =
(TabViewerController) replaceSceneContent("ui/fxml/TabViewer.fxml");
// Gives reference to this object
viewer.setApp(this);
// Draws tablature on screen
viewer.drawTablature();
} catch (Exception e) {
// An error occurred
e.printStackTrace();
}
} |
a6c77802-1f29-4f11-b9d1-66b3837732ec | private Initializable replaceSceneContent(String fxml) throws Exception {
// Create a loader
FXMLLoader loader = new FXMLLoader();
// Stream the fxml resource
InputStream in = Main.class.getResourceAsStream(fxml);
// Load the document
loader.setBuilderFactory(new JavaFXBuilderFactory());
loader.setLocation(Main.class.getResource(fxml));
// Page loading
AnchorPane page;
// Instantiate the scene
try {
page = (AnchorPane) loader.load(in);
} finally {
in.close();
}
// Setup the scene
Scene scene = new Scene(page, 800, 600);
// Sets the scene to the one that was chosen
stage.setScene(scene);
// Resize
stage.sizeToScene();
// Returns the instantiated scene
return (Initializable) loader.getController();
} |
fac9bb05-8b97-4854-883c-20841830e35a | public void setApp(Main application) {
this.application = application;
} |
cb4aa373-4c9a-4eb9-8223-eaeca72b735d | @Override
public void initialize(URL location, ResourceBundle resources) {
} |
03481245-d6a8-4544-aff0-1c3c0f432896 | public void drawTablature() {
// Set the box width and height
boxHeight = anchorPane.getHeight();
boxWidth = anchorPane.getWidth();
tabs = application.getTablature();
// Sets the main label from import file
lblTitle.setText(tabs.getTitle());
LinkedList<Frame> frames = tabs.getFrames();
// drawStringFiller();
drawTablatureLines();
Iterator<Frame> i = frames.iterator();
while (i.hasNext()) {
// Our current frame
Frame curr = i.next();
drawFrame(curr);
}
// Create measure lines so learner can better see what notes are closely related
drawMeasureLines();
lnMarker = drawMarker();
// Setup click event
anchorPane.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
// Scroll
lnMarker.setTranslateX(e.getX());
lastPosition = (long) e.getX();
application.player.seek((long) e.getX());
}
});
} |
9e35410f-0db3-4bcf-b24e-e4430d59aa74 | @Override
public void handle(MouseEvent e) {
// Scroll
lnMarker.setTranslateX(e.getX());
lastPosition = (long) e.getX();
application.player.seek((long) e.getX());
} |
4f0beee6-c570-4466-a8a5-9d67afbe7025 | private void drawFrame(Frame frame) {
int xOffset = xOffset(frame.getOnsetInTicks());
// Notes on the guitar frets
Integer[] notes = frame.guitarStringFrets;
// Create the notes and draw them onto the tablature
for (int i = 0; i < notes.length; i++) {
// A null Integer means that there is no note played on that string
if (notes[i] == null) {
// No note here. Continue.
continue;
} else {
// There is a note
double yOffset = yOffset(6 - i);
// Draw and display the note
drawNote(xOffset, yOffset, notes[i], frame.durations[i]);
}
}
} |
39bbbdb1-afa2-4d6d-965c-fbb13051849e | private void drawTablatureLines() {
// Set up the ratio of the line markers for tablature for the guitar string markers
int i, j, k;
int tabRatioY = (int) (boxHeight / 6);
int tabBorderX = (int) (boxWidth);
int centerY = (int) (boxHeight / 2);
Line l1;
Line l2;
// Add the strings to the tablature
for (i = 0, j = centerY - tabRatioY / 2, k = centerY + tabRatioY / 2; i < 6 / 2; i++, j -=
tabRatioY, k += tabRatioY) {
// Arrange lines
l1 = new Line(tabBorderX, j, boxWidth - tabBorderX, j);
l2 = new Line(tabBorderX, k, boxWidth - tabBorderX, k);
// Color lines
l1.setStroke(Color.BLACK);
l2.setStroke(Color.BLACK);
// Add to the UI
anchorPane.getChildren().addAll(l1, l2);
}
} |
83e8bd99-28df-4f57-a8f1-3f2ba3264744 | public void drawMeasureLines() {
// UI drawing setup
Line l;
Rectangle r;
// Get the measure
int measureLine = tabs.getMeasure();
int tempMeasureLine = 0;
// Iterate across width
for (int i = 0; i < boxWidth; i++) {
// Measure line
l = new Line(tempMeasureLine, 0, tempMeasureLine, boxHeight);
// Displayed on the UI
anchorPane.getChildren().addAll(l);
// Incrememnt tempMeasureLine
tempMeasureLine += measureLine;
}
} |
ec963c76-99d8-4ec9-9d3f-ec6abc9d9bb3 | private void drawStringFiller() {
// Iterate through each string
for (int i = 0; i <= 6; i++) {
// Get the y offset for the string
double yOffset = yOffset((6 - i));
// Displayed to the user
Rectangle r;
int j = i % 2;
if (j != 0) {
// i is even
r = new Rectangle(boxWidth, boxHeight / 6, Color.LIGHTCYAN);
// Set position of rectangle
r.relocate(0, yOffset);
} else {
// i is odd
r = new Rectangle(boxWidth, boxHeight / 6, Color.ALICEBLUE);
// Set position of rectangle
r.relocate(0, yOffset);
}
// Adds to the UI
anchorPane.getChildren().add(r);
}
} |
13fc2714-f672-4c71-8d3d-d7705080006f | private Line drawMarker() {
Line l = new Line(0, 0, 0, boxHeight);
l.setStroke(Color.RED);
anchorPane.getChildren().add(l);
return l;
} |
433111c9-7d0b-4111-abe5-3d69fbdad7a7 | private void drawNote(double xOffset, double yOffset, int fret, long duration) {
// Drawing notes will use rectangles as the main shape
Rectangle r = new Rectangle(duration, boxHeight / 6, noteColor(fret));
// Used to add beautification to the notes
r.setArcWidth(25);
r.setArcHeight(25);
r.setStrokeWidth(1.0);
r.setStroke(Color.BLACK);
r.relocate(xOffset, yOffset);
// The Label will display the fret value
final Label l = new Label("" + fret);
// for centering and displaying the fret number
double labelXValue = xOffset + 10.0;
double labelYValue = yOffset + (boxHeight / 12) - 6;
l.relocate(labelXValue, labelYValue);
l.addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
final Tooltip tooltip = new Tooltip();
tooltip.setText("a note!");
l.setTooltip(tooltip);
}
});
labelCache.add(l);
anchorPane.getChildren().addAll(r, l);
} |
b05dc666-c678-4997-ad20-eafae577f0fd | @Override
public void handle(MouseEvent e) {
final Tooltip tooltip = new Tooltip();
tooltip.setText("a note!");
l.setTooltip(tooltip);
} |
4d45f8c3-c4f8-4957-89ef-dca8e92ac6f0 | private Color noteColor(int fret) {
Color fretColor;
switch (fret % 12) {
case 1:
fretColor = Color.CORAL;
break;
case 2:
fretColor = Color.SALMON;
break;
case 3:
fretColor = Color.BISQUE;
break;
case 4:
fretColor = Color.GOLD;
break;
case 5:
fretColor = Color.PALEGOLDENROD;
break;
case 6:
fretColor = Color.LIGHTGREEN;
break;
case 7:
fretColor = Color.LIGHTSEAGREEN;
break;
case 8:
fretColor = Color.LIGHTBLUE;
break;
case 9:
fretColor = Color.AQUAMARINE;
break;
case 10:
fretColor = Color.VIOLET;
break;
case 11:
fretColor = Color.BLUEVIOLET;
break;
case 12:
fretColor = Color.MEDIUMPURPLE;
break;
default:
fretColor = Color.LIGHTBLUE;
break;
}
return fretColor;
} |
701ec53c-2fcf-4831-9a9c-edd6abbd2cdb | public int xOffset(double onset) {
// Left margin
int shift = 0;
int pixelsPerBeat = 1;
return (int) (shift + onset * pixelsPerBeat);
} |
09c3a3d6-911e-454c-b147-9095f2f32eaa | public double yOffset(int guitarString) {
// Top margin
double shift = -30;
double pixelsBetweenStrings = boxHeight / 6;
return shift + pixelsBetweenStrings * guitarString;
} |
063fdc81-fd1f-4c38-86a9-0c1bf82a9d19 | public void onPlayClicked(ActionEvent e) {
if (application.player.isPlaying()) {
btnPlay.setText("Play");
stopTimer();
lastPosition = application.player.getTickPosition();
application.player.stop();
} else {
btnPlay.setText("Pause");
application.player.stop();
application.player.load(tabs.getScore().getSequence());
application.player.seek(lastPosition);
application.player.play();
final long offsetError = 0;
scrollTimer = new Timer();
scrollTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
lnMarker.setTranslateX(xOffset(application.player.getTickPosition() - offsetError));
}
}, 10, 10);
}
} |
51cd3be4-1df4-4b59-be04-472cc8c8a096 | @Override
public void run() {
lnMarker.setTranslateX(xOffset(application.player.getTickPosition() - offsetError));
} |
bef59954-4fb4-4675-8d40-54a1797c5894 | public void stopTimer() {
System.out.println(scrollTimer.hashCode());
System.out.println(lnMarker.hashCode());
scrollTimer.cancel();
} |
afddcf79-ddfc-419f-a4e9-d453233f20e6 | public void setApp(Main application) {
this.application = application;
} |
df2b392f-16e8-4c7b-80a2-491bea45aaf2 | @Override
public void initialize(URL location, ResourceBundle resources) {
// This is basically our constructor
} |
2bcffcf4-b3f0-43cc-aba1-0f481cf27bca | public void onImportClicked(ActionEvent event) {
// Prompts the user to pick a MIDI file
File file = application.requestMidiFile();
//Check if the user selected a file
if (file == null) {
// User hit cancel
} else {
// User chose successfully
txtImport.setText(file.getName());
fileName = file.getName();
//Disable the import button
btnImport.setDisable(true);
//Enable the tab track
tabTrack.setDisable(false);
//Create factories for displaying in the table
colInstrument.setCellValueFactory(new PropertyValueFactory<TrackTableItem, String>(
"instrument"));
colNumber.setCellValueFactory(new PropertyValueFactory<TrackTableItem, Integer>("number"));
//Gets the chosen track (as a Score)
Score importedScore = MidiReader.readScore(file.getPath());
ObservableList<TrackTableItem> tracks = FXCollections.observableArrayList();
// Add full score
tracks.add(new TrackTableItem(0, "All Tracks", importedScore));
// Add individual tracks
for (int i = 1; i < importedScore.numberOfTracks(); i++) {
Score currentTrack = importedScore.getTrack(i);
tracks.add(new TrackTableItem(i, "", currentTrack));
}
//Add to the UI
tblTracks.setItems(tracks);
}
} |
d4c00c3f-bc38-48f8-bee2-18599bea9f29 | private TrackTableItem(int number, String instrument, Score score) {
this.number = new SimpleIntegerProperty(number);
this.instrument = new SimpleStringProperty(instrument);
this.score = score;
} |
4f00c11a-4b70-4bd0-9083-da0c3457ba47 | public int getNumber() {
return number.get();
} |
39c4a191-ead8-4380-b67b-b50b3eacf69e | public String getInstrument() {
return instrument.get();
} |
b06f2954-ef2a-4749-8aeb-e71c9f32e580 | public Score getScore() {
return score;
} |
004905ce-720e-4fec-b032-6aa4949fb269 | public void onTrackSelected(Event e) {
//Check if the user clicked the first track (play all)
if (tblTracks.getSelectionModel().getSelectedItem().getNumber() == 0) {
// Disable selection of this item
btnPreview.setOpacity(1);
btnTrackSubmit.setOpacity(.5);
btnPreview.setDisable(false);
btnTrackSubmit.setDisable(true);
} else {
// All features are available
btnPreview.setOpacity(1);
btnTrackSubmit.setOpacity(1);
btnPreview.setDisable(false);
btnTrackSubmit.setDisable(false);
}
} |
7f9503c1-4dde-4202-9f10-2095f5290c4e | public void onPreviewRequested(ActionEvent e) {
if (application.player.isPlaying()) {
application.player.stop();
// Display "Preview" in the button
btnPreview.setText("Preview");
} else {
// Select correct track
TrackTableItem item = tblTracks.getSelectionModel().getSelectedItem();
// Create the score from the track
Score score = item.getScore();
// Find the start of the first note and start playing from that point. This solves any issues
// where tracks start late in songs.
application.player.load(score.getSequence());
long start = score.getNotes().get(0).getOnsetInTicks();
System.out.println("Start = " + start);
application.player.seek(start);
application.player.play();
// Display "Stop" in the button
btnPreview.setText("Stop");
}
} |
99294419-8cfe-42dd-a5f7-2eea6a149e7d | public void onTrackSubmit(ActionEvent e) {
// Validate their choice
if (tblTracks.getSelectionModel().getSelectedIndex() == 0) {
// Do nothing. They chose an option that doesn't make sense
return;
}
application.player.stop();
// Get the selected item
TrackTableItem item = tblTracks.getSelectionModel().getSelectedItem();
// Create a score and create the tablature from that score
Score score = item.getScore();
Tablature t = new Tablature(score);
String[] noExtFileName = fileName.split("\\.");
t.setTitle(noExtFileName[0]);
// Switch view to TabViewer
application.gotoTabViewer(t);
} |
cb90a7fc-4d55-4309-b7f6-9f7f3edb745e | public boolean load(Sequence sequence) {
// Validate that the input is not null
if (sequence == null) {
return false;
}
// Stop any existing playback
if (isPlaying()) {
stop();
}
// Attempt to load media using Java's MidiSystem class
try {
// Create a sequencer for the sequence
sequencer = MidiSystem.getSequencer();
sequencer.open();
sequencer.setSequence(sequence);
} catch (InvalidMidiDataException e) {
// Load failed
e.printStackTrace();
return false;
} catch (MidiUnavailableException e) {
// Load failed
e.printStackTrace();
return false;
}
// Load was successful. Return true.
return true;
} |
c0af14c2-4394-451f-9f0f-b5510eff5363 | public boolean play() {
// Ensure that load() has already been called
if (!isLoaded()) {
// Load was not called before calling play
return false;
}
// Start playing
sequencer.start();
isPlaying = true;
return true;
} |
2e56f0cc-2699-4c0b-b6b8-66d6ec9ccc41 | public boolean isLoaded() {
return (sequencer != null);
} |
abac82c1-6b11-4fcb-90d4-797bd7d634a2 | public boolean seek(long onsetInTicks) {
if (!isLoaded()) {
return false;
}
sequencer.setTickPosition(onsetInTicks);
return true;
} |
41051e90-90b9-470f-bce4-9d58f51a5f66 | public void stop() {
if (isPlaying()) {
sequencer.stop();
isPlaying = false;
}
} |
dc561142-ffae-404a-a59c-3703fd0d2177 | public long getTickPosition() {
return sequencer.getTickPosition();
} |
99ab9149-839b-41b7-a268-26666723881f | public long getTotalTickLength() {
return sequencer.getTickLength();
} |
0db06aa6-ff35-4a81-b30a-ddb9921ca105 | public boolean isPlaying() {
return isPlaying;
} |
9a22ce18-b3a5-4a49-8746-8fdf18762400 | public Note(long onsetInTicks, long durationInTicks, int pitch, int channel, int track,
int string, int fret) {
this.onsetInTicks = onsetInTicks;
this.durationInTicks = durationInTicks;
this.pitch = pitch;
this.channel = channel;
this.track = track;
this.string = -1;
this.fret = -1;
} |
bbca0849-9a4a-4b91-8938-ba06ec3f75c9 | public long getOnsetInTicks() {
return onsetInTicks;
} |
970395e2-94fe-477e-836e-43ce2503f4f8 | public void setOnsetInTicks(int onsetInTicks) {
this.onsetInTicks = onsetInTicks;
} |
cd098c5d-6d9e-4ad6-b9e7-a37e715093fb | public long getDurationInTicks() {
return durationInTicks;
} |
2ba54446-20b2-4626-a157-90d515f5c230 | public void setDurationInTicks(int durationInTicks) {
this.durationInTicks = durationInTicks;
} |
b84c4ab6-1560-439c-b128-3f6886bc358d | public int getPitch() {
return pitch;
} |
853eb18c-7357-471a-8d31-21aff4da6e70 | public void setPitch(int pitch) {
this.pitch = pitch;
} |
c577df6e-f57e-4f52-bd93-66a060269406 | public int getChannel() {
return channel;
} |
b580ced7-6ad0-4dcd-b3c3-1077623f02ec | public void setChannel(int channel) {
this.channel = channel;
} |
408a2787-793b-466f-8665-060d0135dfdd | public int getTrack() {
return track;
} |
b0682043-ceaf-49c9-8b9e-667ff4c26ac8 | public void setTrack(int track) {
this.track = track;
} |
d793f811-cbc2-49da-b005-3d98e6951e40 | public void setOnsetInTicks(long onsetInTicks) {
this.onsetInTicks = onsetInTicks;
} |
542c7242-1858-4dff-b0a5-98ba965c663e | public void setDurationInTicks(long durationInTicks) {
this.durationInTicks = durationInTicks;
} |
8ecc227d-4075-411c-b22e-04238e43b32a | public int getStringNo() {
return string;
} |
d71b7e13-eac1-4748-a1a9-3b1fbd6cf70d | public void setString(int string) {
this.string = string;
} |
2fe6d4e4-d1fe-41da-8854-68151a52c1ba | public int getFret() {
return fret;
} |
602817e3-810c-4f29-ad21-897bd4bb79bb | public void setFret(int fret) {
this.fret = fret;
} |
406cbd14-12c8-4a85-be2a-d582319c0b47 | @Override
public String toString() {
return "Note [string=" + string + ", fret=" + fret + ", onsetInTicks=" + onsetInTicks
+ ", durationInTicks=" + durationInTicks + ", pitch=" + pitch + ", channel=" + channel
+ ", track=" + track + "]";
} |
fbb14b3f-31f7-4d18-a7f9-86a52c7deffe | @Override
public int compareTo(Note note) {
if (this.getPitch() < note.getPitch())
return -1;
else if (this.getPitch() == note.getPitch())
return 0;
else
return 1;
} |
0e776f6c-d0e6-42ee-9ab0-b033de432758 | public Frame(double currentOnset) {
this.onsetInTicks = currentOnset;
} |
44341ca9-f4f7-493e-a598-191be5e52dd6 | public void addNote(Note n) {
notes.add(n);
} |
748f65c4-d95c-4ba3-b2c2-3216e9d233da | public HashSet<Note> getNotes() {
return notes;
} |
622a5270-1633-4cbe-ab3a-cd6cf185815f | public double getOnsetInTicks() {
return onsetInTicks;
} |
ec94d181-a66b-4688-bc62-f232f9aeb7be | public Score(Sequence seq) throws SequenceDivisionTypeException {
// Check to see if the sequence is valid
if (isNull(seq)) {
// Sequence given is invalid. Throw an exception.
throw new RuntimeException("The sequence given is invalid.");
}
// Store the sequence given
this.seq = seq;
/*
* Parse the sequence into a easy to manipulate PianoRoll object.
*
* If seq is invalid, a SequenceDivisionTypeException will be thrown here.
*/
PianoRoll roll = PianoRollViewParser.parse(seq);
// Get the notes as NotesInMidi objects
NotesInMidi[] notes = roll.getNotes();
// Convert the PianoRoll object into 1D and 2D arrays
double[][] noteArray = roll.getNotesDoubles();
// Update variables to point to the parsed arrays
this.notes = noteArray;
this.notes1D = notes;
this.notesList = getNotes();
} |
481a63d4-928f-4c8a-85a8-725d66fa9715 | private boolean isNull(Object obj) {
return obj == null;
} |
87beb554-510b-4c8f-8fce-c979a0ef3715 | public int numberOfTracks() {
return seq.getTracks().length;
} |
5c7d2ba8-a189-4901-85b8-c35ba83d6b66 | public Score getTrack(int track) {
if (track < 0) {
return null;
}
// The desired track as a Track object
Track t = seq.getTracks()[track];
// Our output
Sequence requested;
try {
// Get division and resolution for the Sequence object
float divType = seq.getDivisionType();
// Resolution (ticks per second)
int ticksPerSecond = seq.getResolution();
// Construct a new Sequence
requested = new Sequence(divType, ticksPerSecond);
// Update track information
Track newt = requested.createTrack();
for (int i = 0; i < t.size(); i++) {
// Add the midi events to the track newt
newt.add(t.get(i));
}
try {
// Score may throw an exception
return new Score(requested);
} catch (SequenceDivisionTypeException e) {
// An error occurred. Return null.
e.printStackTrace();
return null;
}
} catch (InvalidMidiDataException e) {
// An error occurred. Return null
return null;
}
} |
3acd32e3-be26-4075-a6a0-1e390f3de1c2 | public Sequence getSequence() {
return seq;
} |
4b7394e9-d057-4fff-b987-06f548a1b249 | public ArrayList<Note> getNotes() {
ArrayList<Note> output = new ArrayList<Note>();
Note note = null;
for (int i = 0; i < this.notes1D.length; i++) {
// Pull value for the note object
NotesInMidi curr = this.notes1D[i];
// Save each of the attributes for construction of a Note object
long onset = curr.getStartTick();
long duration = curr.getDurationTick();
int pitch = curr.getNote();
int channel = curr.getChannel();
int track = curr.getTrackNumber();
// Create the note from the data
note = new Note(onset, duration, pitch, channel, track, 0, 0);
// Add it to the ArrayList
output.add(note);
}
// Return the notes as a list of Note objects
return output;
} |
2065916c-70a3-4633-a885-36b03a9c5a30 | public int getTimingResolution() {
int timeRes = seq.getResolution();
return timeRes;
} |
62e9d715-f0e2-4d63-8fb5-623e7b284835 | public String getTitle() {
return title;
} |
f01f6db2-0e0c-4dc7-b367-5d7254fbcb63 | public void setTitle(String title) {
this.title = title;
} |
8c19a345-83c8-4856-a975-d4cad419931e | public Tablature(Score score) {
this.score = score;
parse();
} |
954a08e4-b670-41db-b753-b00409a275f7 | public LinkedList<Frame> getFrames() {
return frames;
} |
d5ba213b-dbbf-408c-a135-ab5aaf5434a2 | public Score getScore() {
return score;
} |
9bd3a4d2-7b1e-4af7-8b1b-c41e6bb7e85b | private void parse() {
// Notes for parsing
ArrayList<Note> notes = score.getNotes();
// Frames for saving into
LinkedList<Frame> frames = new LinkedList<Frame>();
// Convert to {@link Note} ArrayList
notes = createTabNumbers(notes, PicCreator.START_PITCH, PicCreator.END_PITCH);
// Bypass all incorrectly formated MIDI data from the MIDI file
for (Note note : notes) {
if (note.getStringNo() < 0) {
continue;
}
// Add a frame to the frames LinkedList
if (frames.isEmpty() || frames.getLast().getOnsetInTicks() != note.getOnsetInTicks()) {
frames.add(new Frame(note.getOnsetInTicks()));
}
// Add the note to the {@link Frame}
Frame currFrame = frames.getLast();
currFrame.durations[note.getStringNo()] = note.getDurationInTicks();
currFrame.guitarStringFrets[note.getStringNo()] = note.getFret();
}
// Update pointers to the modified frame
this.frames = frames;
} |
4d8ef69b-c4ae-48a9-9caf-e8846885b6ac | public int getMeasure() {
int ticksPerQuarterNote = score.getTimingResolution();
int measure = ticksPerQuarterNote * 4;
return measure;
} |
488499cb-8c80-47d9-928d-5b453772b461 | public void print() {
for (int i = 0; i < 30; i++) {
Frame curr = frames.get(i);
// curr.print();
}
} |
0837e103-987f-4f8d-82d2-13260bd69886 | public static ArrayList<Note> createTabNumbers(ArrayList<Note> list, int min, int max) {
// Min and max cannot be negative numbers
if (min < 0 || max < 0) {
return null;
}
// Create the temporary ArrayList that will be returned
ArrayList<Note> notesList = new ArrayList<Note>(list.size());
// Counters for the fret and strings
int fret = 0;
int stringNo = 0;
/*
* Loop through the list of notes
*/
for (int j = 0; j < list.size(); j++) {
// Relevant note for this iteration
Note curr = list.get(j);
int currPitch = curr.getPitch();
/*
* Iterate through from min to max
*/
for (int i = min; i < max; i++) {
// If we have reached the pitch of the current note
if (i == currPitch) {
// Confirm the current string and fret number
curr.setString(stringNo);
curr.setFret(fret);
// Add the corrected note to the notesList
notesList.add(curr);
// Reset the counter and string number to 0 for the new note
fret = 0;
stringNo = 0;
break;
} else if (fret == 7 && stringNo != 5) {
// Increase string number and reset the fret counter
fret = 0;
stringNo++;
// Must account for the reset of fret number
if (stringNo != 4) {
// Every string other than the G string
i -= 3;
} else {
// Accounts for the G String
i -= 4;
}
} else {
// Increment fret
fret++;
}
}
}
return notesList;
} |
77d327ca-34ac-4e4e-b345-fe0d0c8cc9a6 | public static Score readScore(String midiFilePath) {
if (!hasReadAccessToPath(midiFilePath)) {
return null;
}
// Create the file and pull from the passed file path
File midiFile = new File(midiFilePath);
// Test if the path exists
if (!midiFile.exists()) {
// The file does not exist. Return false.
return null;
}
try {
// Pull the MIDI sequence for the file
Sequence seq = MidiSystem.getSequence(midiFile);
// Return the data as a Score object
return new Score(seq);
} catch (Exception e) {
// An error occurred
e.printStackTrace();
return null;
}
} |
d886725b-5c80-4d11-a516-64ca6894aa1c | private static boolean hasReadAccessToPath(String midiFilePath) {
// Ensure the path is valid
if (!isValidPath(midiFilePath)) {
// Path is invalid
return false;
}
// Creates a File object using the path
File midiFile = new File(midiFilePath);
return midiFile.exists();
} |
387e5105-853e-427b-b9bc-c2b95a7fccf4 | private static boolean isValidPath(String midiFilePath) {
if (midiFilePath == null || midiFilePath == "") {
return false;
} else {
// Creates a File object using the path
File midiFile = new File(midiFilePath);
return midiFile.exists();
}
} |
db3f1838-bb7b-46ca-a393-1bced5f55c1c | public static void generatePicture(ArrayList<Note> notesList) throws Exception {
transposeToGuitarRange(notesList);
createTabNumbers(notesList, START_PITCH, END_PITCH);
} |
2d1e218b-2701-4a6f-a5c1-7c14ddc4e184 | private static void transposeToGuitarRange(ArrayList<Note> list) {
for (Note note : list) {
int pitch = note.getPitch();
if (pitch < 40) {
while (pitch < 40) {
pitch += 12;
}
} else if (pitch > 88) {
while (pitch > 88) {
pitch -= 12;
}
}
note.setPitch(pitch);
}
} |
62bda242-3d2b-45e9-9e80-d7d1708087d8 | public static ArrayList createTabNumbers(ArrayList<Note> list, int min, int max) {
// What is the purpose of this?
boolean hasBeenWriten = true;
sameNotes = new ArrayList<Note>(list.size());
int counter, stringNo;
mainListIndex = 0;
stackListIndex = 0;
/*
* Loop through the list of notes
*/
for (int j = 0; j < list.size(); j++) {
// Relevant note for this iteration
Note curr = list.get(j);
int currPitch = curr.getPitch();
counter = 0;
stringNo = 0;
/*
* Iterate through from min to max
*/
for (int i = min; i < max; i++) {
// If we have reached the pitch of the current note
if (i == currPitch) {
ArrayList<Note> stack = new ArrayList<Note>(10);
// Confirm the current string and fret number
curr.setString(stringNo);
curr.setFret(counter);
// I do not know what this means
stack.add(stackListIndex, curr);
stackListIndex++;
// I do not understand
while (j + 1 < list.size()) {
// Note following curr
Note next = list.get(j + 1);
// I'm lost.
if (next.getOnsetInTicks() == curr.getOnsetInTicks() && stringNo != 5) {
stack.add(stackListIndex, next);
stackListIndex++;
i++;
j++;
} else {
sameNotes.add(mainListIndex, stack);
mainListIndex++;
break;
}
}
counter = 0;
stringNo = 0;
stackListIndex = 0;
} else if (counter == 7 && stringNo != 5) {
counter = 0;
stringNo++;
if (stringNo != 4) {
i -= 3;
} else {
i -= 4;
}
} else {
counter++;
}
}
}
if (hasBeenWriten) {
// PicUtil.drawTab(sameNotes);
hasBeenWriten = false;
}
return sameNotes;
} |
1baf5e26-e31a-4bf3-9981-b19d6129904f | public static void updateNextNote(Note note, Note compare) {
int pitch = compare.getPitch();
int string = 0;
int fret = 0;
for (int i = START_PITCH; i < END_PITCH; i++) {
if (i == pitch && string != note.getStringNo()) {
compare.setString(string);
compare.setFret(fret);
return;
} else if (i == pitch && string == note.getStringNo()) {
compare.setString(-1);;
return;
} else if (fret == 7 && string != 5) {
fret = 0;
string++;
} else {
fret++;
}
}
} |
75fd4805-541f-4a3a-a40d-505988e174d4 | static public void drawTab(ArrayList list) {
try {
int width = list.size() * 50, height = 500, index = 50;
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D ig2 = bi.createGraphics();
Font font = new Font("TimesRoman", Font.BOLD, 20);
ig2.setFont(font);
ig2.setPaint(Color.black);
printLines(ig2, width);
for (int i = 0; i < list.size(); i++) {
ArrayList<Note> secondList = (ArrayList<Note>) list.get(i);
printSecondList(secondList, index, ig2);
index += 50;
}
ImageIO.write(bi, "PNG", new File("test.png"));
} catch (Exception ie) {
ie.printStackTrace();
}
} |
9bda085b-f3e7-4540-afe0-c59b6226239b | private static void printLines(Graphics2D ig2, int width) {
for (int i = 0; i < width; i++) {
for (int j = 200; j < 500; j += 50) {
ig2.drawString("-", i, j);
}
}
} |
758c3673-a720-4d9a-be69-56d2ba277999 | private static void printSecondList(ArrayList<Note> secondList, int index, Graphics2D ig2) {
for (Note note : secondList) {
if (note.getStringNo() < 0) {
continue;
}
int height = getHeight(note.getStringNo());
ig2.drawString(note.getFret() + "", index, height);
}
} |
e6317980-4703-4a7b-b4c2-9f179f307f9f | private static int getHeight(int string) {
if (string == 0)
return 450;
else if (string == 1)
return 400;
else if (string == 2)
return 350;
else if (string == 3)
return 300;
else if (string == 4)
return 250;
else if (string == 5)
return 200;
else
return 0;
} |
56f8cb60-ad8c-4806-b86f-0ed8874874b5 | public static void main(String[] args) {
JFrame container = new JFrame("SpaceWar");
container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
container.setContentPane(new SpacePanel());
// Hides the border in our game
container.setUndecorated(true);
container.setResizable(false);
container.pack();
container.setLocationRelativeTo(null);
container.setVisible(true);
} |
94a06c59-56aa-451d-881c-baa8936322ac | public Text (double x, double y, long time, String s) {
this.x = x;
this.y = y;
this.time = time;
this.s = s;
start = System.nanoTime();
//start = (System.nanoTime() - start) / 1000000;
} |
fd663c1e-5321-4fa6-a105-5ef420df2205 | public boolean update () {
long elapsed = (System.nanoTime() - start) / 1000000;
if (elapsed > time)
return true;
return false;
} |
9d70b61e-ae90-4901-8c5b-3f743856f2b1 | public void draw (Graphics2D g) {
g.setFont(new Font("Century Gothic", Font.PLAIN, 12));
long elapsed = (System.nanoTime() - start) / 1000000;
//int alpha = (int) (255 * Math.sin(Math.PI * elapsed / time));
//if (alpha > 255) alpha = 255;
g.setColor(new Color(255, 255, 255, 128));
int length = (int) g.getFontMetrics().getStringBounds(s, g).getWidth();
g.drawString(s, (int) (x - (length / 2)), (int) y);
} |
bc2da04b-3933-4748-8622-83dd389e3281 | public Player () {
x = SpacePanel.width / 2;
y = SpacePanel.height - 100;
r = 25;
dx = 0;
dy = 0;
speed = 5;
lives = 3;
color1 = Color.WHITE;
color2 = Color.RED;
firing = false;
firingTimer = System.nanoTime();
firingDelay = 200;
recovering = false;
recoveryTimer = System.nanoTime();
score = 0;
if (imageUp == null) imageUp = new Generals().loadImg("/img/hero/hero-up.png");
if (imageUpTrans == null) imageUpTrans = new Generals().loadImg("/img/hero/hero-up-transp.png");
image = imageUp;
} |
42457a18-dc68-4654-8b80-378466e81fed | public void update () {
if (left) dx = -speed;
if (right) dx = speed;
if (up) dy = -speed;
if (down) dy = speed;
x += dx;
y += dy;
// setting the frame limit
if (x < r) x = r;
if (y < r) y = r;
if (x > SpacePanel.width - r) x = SpacePanel.width - r;
if (y > SpacePanel.height - r) y = SpacePanel.height - r;
dx = 0;
dy = 0;
if (firing) {
long elapsed = (System.nanoTime() - firingTimer) / 1000000;
if (elapsed > firingDelay) {
firingTimer = System.nanoTime();
if (powerLevel < 2)
SpacePanel.bullets.add(new Bullet(270, (x + 10), y));
else
if (powerLevel < 3) {
SpacePanel.bullets.add(new Bullet(270, (x + 10) + 5, y));
SpacePanel.bullets.add(new Bullet(270, (x + 10) - 5, y));
} else
if (powerLevel < 4) {
SpacePanel.bullets.add(new Bullet(265, (x + 10) - 5, y));
SpacePanel.bullets.add(new Bullet(270, (x + 10), y));
SpacePanel.bullets.add(new Bullet(277, (x + 10) + 5, y));
} else {
SpacePanel.bullets.add(new Bullet(264, (x + 10) - 3, y));
SpacePanel.bullets.add(new Bullet(267, (x + 10) - 3, y));
SpacePanel.bullets.add(new Bullet(270, (x + 10), y));
SpacePanel.bullets.add(new Bullet(273, (x + 10) + 3, y));
SpacePanel.bullets.add(new Bullet(276, (x + 10) + 3, y));
}
}
}
// Time, i am invencible (2 s)
if (recovering) {
long elapsed = (System.nanoTime() - recoveryTimer) / 1000000;
if (elapsed > 2000) {
recovering = false;
recoveryTimer = 0;
}
}
} |
2d531097-2db8-4ce8-af59-5490ad17bb1e | public void draw (Graphics2D g) {
if (recovering)
image = imageUpTrans;
else
image = imageUp;
g.drawImage(image, x - r, y - r, null);
} |
f96514c2-3e70-4aef-8229-e8b1b2308284 | public void setLife (int life) {lives = life;} |
28562b71-7d77-42a2-ac0c-7672a7670c5a | public void setLeft (boolean direction) {left = direction;} |
61f388b1-a75d-485d-9646-b9d166b476f1 | public void setRigth (boolean direction) {right = direction;} |
71759d7c-8fca-4a29-a576-f6b0b5821641 | public void setUp (boolean direction) {up = direction;} |
341c9b81-386c-453e-abc3-64e3453288f5 | public void setDown (boolean direction) {down = direction;} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.