160 likes | 243 Views
JPiano is a virtual keyboard enabling music composition, learning, and tinkering with notes. Learn music concepts, use formulas for pitch and duration, and explore algorithms. Programmed in Java, it offers code examples, file extension .pno, limitations, bugs, and future work. Dive into the Note model, music formulas, bugs, and enhancements. Enhance your music skills with JPiano!
E N D
JPIANO By Adam Harlow
Overview • What is JPiano? • Program design • Some basic music concepts • The Note model • Formulas and algorithms used • The JPiano file extension • Code examples • Limitations and bugs • Future work, Conclusion
What is JPiano? • A virtual keyboard spanning one scale • A composing tool • A keyboard learning tool • A toy for tinkering with notes
Some basic music concepts 4 4 Number of beats Total number of beats per measure Value of beat Duration of a note, usually a multiple of four (4, 8, 16) Sharp Raises note by one semitone Dot Increases duration of a note by half
The Note model • A musical note has two basic properties: • Duration • Tone • The Note class stores these variables, among others, in the model.
The Note model (cont’d) 4 4 B G# A E Vector: (qtr)B (qtr)G# (8th)A (qtr*)E Note: The note vector stores Note objects only. The output you see here is stored in a separate String vector.
Formulas and algorithms used • Length of one whole note • duration = 4*(60/bpm)*1000 • Pitch calculation • pitch = MIN_PITCH+(12*octave) • MIN_PITCH at C0 is 12 • Regular expression pattern for text output • \([(wh)(hf)(qtr)(8th)(16th)]\*?\)(r|[ABCDEFGc]\#?)
The JPiano file extension (.pno) • Output is generated based on each note’s attributes and is stored into a Note vector. • File uses mentioned regex pattern to read and write from a file. • Can be any length. • Can be created by hand in a text file.
Note constructor public Note(intbpm, int value, char noteLetter) { this.setBpm(bpm); try { assignDurations(); } catch (NoteDurationExceptionnde) {} try { this.setValue(value); } catch (UndefinedNoteExceptionune) {} this.setNoteLetter(noteLetter); this.isDotted(); this.isSharp(); }
Assigning durations from bpm public void assignDurations() throws NoteDurationException{ double ibpm = this.getBpm().intValue(); //note duration in milliseconds is 4*(60/bpm)*1000 defaultDuration= 4*(60/ibpm)*1000; if (defaultDuration <= 0) { throw new NoteDurationException(); } for (Values v : Values.values()) { durations[v.ordinal()] = defaultDuration; defaultDuration /= 2; } }
Part of the “insert” Action if (!toggle) { noteString= noteString + "(" + note.getPrefix(); if (note.isDotted()) { noteString= noteString + "*)"; else noteString= noteString + ")"; noteString= noteString + note.getNoteLetter(); if (note.isSharp()) noteString= noteString + "#"; noteString= noteString + " "; noteText.add(noteString); output.append(noteText.lastElement()); note.setNoteOutput(output.getText()); SimpleSynthsynth = new SimpleSynth(); synth= new SimpleSynth((int)note.getDuration(note.getValue()), note.getPitch()); } notes.add(note);
Sound playback public SimpleSynth(int duration, int pitch) { //receives parameters from Note attributes … MidiMessagenoteOn = getNoteOnMessage(pitch); rcvr.send(noteOn, 0); try { Thread.sleep(duration); } catch(InterruptedExceptione) { e.printStackTrace(); } MidiMessagenoteOff= getNoteOffMessage(pitch); rcvr.send(noteOff, 0); }
Limitations and bugs • Currently no sound output for “Free Play” • Cannot play chords or simultaneous key presses • Octave is not represented in text output • Key binding is wonky at best • Sound cuts off/dies easily if keys are pressed too quickly • No time signatures are supported • Cannot do odd note groupings (e.g. triplets)
Future work • Fix the “Free Play” bug • Ensure that notes are properly removed from text area as well as the vectors • Add ability to change instruments • Implement multi-threading in synthesizer • Make a cleaner control layout
Conclusion, final thoughts • Object Oriented Programming is ideal for many music-based programs • Can probably make other types of programs with Note model, such as a chord calculator • JPiano did not satisfy original expectations, but came pretty close