The following steps will create an Eclipse project containing source code for Problem Set 1:

Similar documents
BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1

JavaCC: SimpleExamples

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

IBM WebSphere Java Batch Lab

EMC Documentum Composer

1. Go to the URL Click on JDK download option

CMPSCI 187 / Spring 2015 Hanoi

Prerequisites for Eclipse

Eclipse Setup. Opening Eclipse. Setting Up Eclipse for CS15

CS664 Compiler Theory and Design LIU 1 of 16 ANTLR. Christopher League* 17 February Figure 1: ANTLR plugin installer

Do this by creating on the m: drive (Accessed via start menu link Computer [The m: drive has your login id as name]) the subdirectory CI101.

Setting Up the Development Environment

Packaging Your Program into a Distributable JAR File

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

RTMS - Software Setup

EMC Documentum Composer

Introduction to Computation and Problem Solving

Lab Android Development Environment

Introduction to Eclipse

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

Install and Configure ANTLR 4 on Eclipse and Ubuntu

1. The Apache Derby database

PART 1. Eclipse IDE Tutorial. 1. What is Eclipse? Eclipse Java IDE

CMPSCI 187 / Spring 2015 Hangman

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

CS520 Setting Up the Programming Environment for Windows Suresh Kalathur. For Windows users, download the Java8 SDK as shown below.

In this lab we will practice creating, throwing and handling exceptions.

Creating a new CDC policy using the Database Administration Console

, has the form T i1i 2 i m. = κ i1i 2 i m. x i1. 1 xi2 2 xim m (2)

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

- 1 - Handout #33 March 14, 2014 JAR Files. CS106A Winter

Just Enough Eclipse What is Eclipse(TM)? Why is it important? What is this tutorial about?

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:

Use the Apple menu to change settings, get Mac OS X software, open recent items, and restart or shut down your computer.

Certified Core Java Developer VS-1036

Eclipse on Cell phones?

ASSIGNMENT 5 Objects, Files, and a Music Player

Programming in C++ 4. The lexical basis of C++

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

CMPSCI 187 / Spring 2015 Sorting Kata

IBM Mobile Portal Accelerator Enablement

CS 553 Compiler Construction Fall 2009 Project #1 Adding doubles to MiniJava Due September 8, 2009

Getting Started with Eclipse for Java

Starting In Java With JPT in Eclipse

1.00 Lecture 2. What s an IDE?

If you are going to form a group for A2, please do it before tomorrow (Friday) noon GRAMMARS & PARSING. Lecture 8 CS2110 Spring 2014

UNIVERSITY OF CALIFORNIA

CSCI 201L Written Exam #1 Fall % of course grade

S D K Q U I C K S T A R T

Java Bytecode (binary file)

Laboratory 1: Eclipse and Karel the Robot

Introduction to Computers and Java

Hadoop Tutorial. General Instructions

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm)

Building Java Programs. Introduction to Programming and Simple Java Programs

Algorithms & Datastructures Laboratory Exercise Sheet 1

Using Eclipse Europa - A Tutorial

CS2112 Fall Assignment 4 Parsing and Fault Injection. Due: March 18, 2014 Overview draft due: March 14, 2014

Microsoft Word. Introduction

ASSIGNMENT 5 Objects, Files, and More Garage Management

Import an Xcode project into WOLips

Com S 227 Assignment Submission HOWTO

For live Java EE training, please see training courses at

CS 553 Compiler Construction Fall 2007 Project #1 Adding floats to MiniJava Due August 31, 2005

Assignment Submission HOWTO

How to Install (then Test) the NetBeans Bundle

Web API Lab folder 07_webApi : webapi.jsp your testapijs.html testapijq.html that works functionally the same as the page testapidomjs.

Getting Started with Eclipse/Java

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Configuring the Android Manifest File

1 Lexical Considerations

Chapter 3 How to use HTML5 and CSS3 with ASP.NET applications

ALTIRIS Console 6.5 Overview

Even though we created a folder for the workspace, we still have to let JCreator do the same. So click File, New, and then Blank Workspace.

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

Fundamentals: Expressions and Assignment

Using Karel with Eclipse

NetBeans Tutorial. For Introduction to Java Programming By Y. Daniel Liang. This tutorial applies to NetBeans 6, 7, or a higher version.

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

WPS Workbench. user guide. "To help guide you through using the WPS user interface (Workbench) to create, edit and run programs"

Lesson 10: Quiz #1 and Getting User Input (W03D2)

Assignment 1. Application Development

ActiveSpaces Transactions. Quick Start Guide. Software Release Published May 25, 2015

11 Using JUnit with jgrasp

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

Downloading Tweet Streams and Parsing

Evaluation Guide - WebSphere Integration

CONFIGURING SAFE V4.0 IN THE IBM COLLABORATIVE LIFECYCLE MANAGEMENT

The purpose of this tutorial is to introduce you to the Construct 2 program. First, you will be told where the software is located on the computer

Installing and Running the Google App Engine On a Macintosh System

CSE 401 Final Exam. December 16, 2010

EMC Documentum Composer

Centroid 2.0 User Guide. Version 1.0

Setup and Getting Startedt Customized Java EE Training:

Mobile Application Workbench. SAP Mobile Platform 3.0 SP02

Transcription:

Problem Set 1 Programming Music Out: 27 August Due: Monday, 1 Sept (beginning of class) Collaboration Policy - Read Carefully For this problem set, you should work alone, but feel free to ask other students for help and offer help to other students. It is a violation of class pledge policy to use answers from previous years. Purpose Learn basics of programming in Java Get familiar with the Eclipse integrated development environment (IDE) Provide some exposure to Java class interactions and object oriented design Background Part of the richness of Java is the large number of libraries and APIs that are available for free. In many ways the utility of Java is defined more by the extras that are available for it than the core language itself. One API that is fun to play with is the music generator JFugue. Its homepage can be found at: http://www.jfugue.org/index.html. JFugue is open source software, distributed under the LGPL license http://www.gnu.org/copyleft/lesser.html. A nice feature of JFugue is that it allows a user to submit a pattern a string with a fairly simple syntax that is then converted to music. JFugue s features are fairly extensive, as you ll discover as you play with the code. In this assignment you will be installing JFugue, exploring it, and then modifying it, all in the Eclipse integrated development environment. Running jfugue The following steps will create an Eclipse project containing source code for Problem Set 1: 1. Open Eclipse by clicking on Start SEAS Java Apps Eclipse 2. Inside the Eclipse window, click on File New Java Project. The Create a Java Project dialog box will appear. 3. In the Project name: box enter, jfugue. In the Project Layout pane, select Create separate folders for sources and class files. Click Next> and then Finish on the next dialog box. Now, you should see the Package Explorer view, containing the jfugue folder. 4. Click on + next to jfugue in the package explorer You should see src and JRE system library in the jfugue directory 5. Right click on src and select NEW PACKAGE 6. Name your package org.jfugue

7. Create a J:\CS205 directory 8. Open a browser and navigate to: http://www.jfugue.org/index.html 9. Select download from the list on the left (Explore a little first) 10. Download jfugue-4.0.2-src.zip into J:\CS205. 11. Unzip jfugue-4.0.2-src.zip in place --a directory named org is created 12. Drag org and drop it on the src directory for jfugue in the package explorer. You should see two directories (packages in this case) created in src : org.jfugue org.jfugue.extras 13. In your browser, navigate to http://www.xom.nu/ 14. Download the third item listed, Jar file, (Core packages only) into J:\CS205. This action will create the file xom-1.1.jar 15. In the Eclipse package explorer, right click on project jfugue 16. Select properties 17. Select Java Build Path from the list in the left hand column. 18. Click on the tab libraries 19. Select the Add External JARs button 20. Navigate to J:\CS205 and select xom-1.1.jar 21. Select OPEN in the file selection dialog, and then select OK. All of the little red x's in the jfugue directory should go away. 22. Click on the + to the left of the src directory for your project jfugue in the package explorer 23. Right click on the org.jfugue package directory within the src directory 24. Select NEW CLASS 25. Name your class MyMusicAPP and select FINISH 26. In the editor window for MyMusicAPP enter the following text just after the line: public class MyMusicApp public static void main(string[] args) Player player = new Player(); Pattern pattern = new Pattern("C D E F G A B C6w"); player.play(pattern); 27. Select FILE SAVE Whenever you make a change to a Java source file and save it, the changes are automatically compiled. If you want to force Eclipse to rebuild the entire project, select Project Clean. 28. Select RUN OPEN RUN DIALOG... 29. Project should be named jfugue and Main class should be named org.jfugue.mymusicapp 30. Plug in your headphones and select RUN

You should hear the eight notes listed in the player pattern (scale). The jfugue music programmer The implementation of the JFugue music programmer contains modules for parsing and interpreting input strings (e.g. C D E F G A B C6w in the example above), checking them for errors, setting up timing and parallel notes (e.g. chords) and sending them off to parser listeners which can turn them into music, create sheet music, create a graphical display, etc. Currently, the program only plays music. Here we provide a description of some of the more important classes. At this time you do not need to understand the details of how these classes are implemented. Player.java This is the top level class for the implementation of JFugue. It receives user specified input patterns denoting a musical sequence and sends them off to a parser and interpreter. The author of JFugue, David Koelle, has published a book, The Complete Guide to JFugue. Excerpts from the first two chapters can be found here: http://www.jfugue.org/book.html Take a look at the excerpts from chapter 2, Using the JFugue Music String. There you will find a description of the grammar (rules for making legal strings) for patterns, and an overview of all of the actions that can be expressed in patterns. Parser.java Processing of input patterns takes place in the parser class hierarchy. The parser class is the root of this hierarchy. It defines a base set of actions (methods) that can be applied no matter what patterns are parsed to do (musical output, music notes, graphics, etc.). Such actions include management of debug tracing, setting up listeners to the parser s output, and sending inputs to the listeners. MidiParser.java, MusicStringParser.java and MusicXmParser.java Using object-oriented methodology, which we ll discuss in detail this semester, JFugue creates extensions ( extends ) the parser class in multiple directions. You ll find the MidiParser, MusicStringParser and MusicXmParser classes all extend the parser class, each providing specific capabilities for the functions suggested by their names. Our focus will be on MusicStringParser. public final class MusicStringParser extends Parser Open the MusicStringParser class in the Eclipse editor and browse through it. Having read the excerpts from chapter 2 of The Complete Guide to JFugue, you should be seeing some code that makes sense, in the context of the chapter 2 discussions. For example, this method: private void parsetoken(string s) throws JFugueException // If there are any spaces, get out if (s.indexof(" ")!= -1) throw new JFugueException(JFugueException.PARSER_SPACES_EXC,s,s);

s = s.touppercase(); trace("--------processing Token: ",s); switch(s.charat(0)) case 'V' : parsevoiceelement(s); case 'T' : parsetempoelement(s); case 'I' : parseinstrumentelement(s); case 'L' : parselayerelement(s); case 'K' : parsekeysignatureelement(s); case 'X' : parsecontrollerelement(s); case '@' : parsetimeelement(s); case '*' : parsepolypressureelement(s); case '+' : parsechannelpressureelement(s); case '&' : parsepitchbendelement(s); case ' ' : parsemeasureelement(s); case '$' : parsedictionaryelement(s); case 'A' : case 'B' : case 'C' : case 'D' : case 'E' : case 'F' : case 'G' : case 'R' : case '[' : parsenoteelement(s); default : // Unknown characters are okay receives tokens one at a time, checks them for simple error conditions (e.g. embedded spaces) and then calls the right method for processing depending on the token value. You can see that the eight notes, A-G, (as well as R and [ ) result in a call to parsenoteelement. The parse-x- Element methods all lead to calls to a fire event which results in a parser listener being told about the musical event. A parser listener that is a musical note generator will cause you to hear a note through the computer speakers (or headphones). Note, at the end of the switch statement, that if the user has placed an unknown character at the beginning of a token, the music parser ignores it without warning the user. Note also that Java does have a mechanism for reporting exceptions, as can be seen at the beginning of parsetoken. The parsenoteelement method is one of the more interesting ones because notes can be fairly complex. parsenoteelement contains a fairly consolidated view of all of the possibilities for a note: private void parsenoteelement(string s) throws JFugueException NoteContext context = new NoteContext(); while (context.existanothernote) int index = 0; int slen = s.length(); index = parsenoteroot(s, slen, index, context);

index = parsenoteoctave(s, slen, index, context); index = parsenotechord(s, slen, index, context); computenotevalue(context); index = parsenotechordinversion(s, slen, index, context); index = parsenoteduration(s, slen, index, context); index = parsenotevelocity(s, slen, index, context); s = parsenoteconnector(s, slen, index, context); firenoteevents(context); class NoteContext boolean isrest boolean isnumericnote boolean ischord boolean isfirstnote = true; boolean isnatural boolean existanothernote = true; boolean anothernoteissequential boolean isstartoftie boolean isendoftie byte[] halfsteps = new byte[5]; byte numhalfsteps = 0; byte notenumber = 0; int octavenumber = 0; double decimalduration = 0.0; long duration = 0L; byte attackvelocity = Note.DEFAULT_VELOCITY; byte decayvelocity = Note.DEFAULT_VELOCITY; public NoteContext() for (int i=0; i < 5; i++) halfsteps[i] = 0; You can see from the NoteContext class that notes can be rests, they can be specified numerically or by letter, they may appear alone, or as a part of a sequence (where the first note has distinct characteristics), velocity can be specified, etc. Playing with Notes Users may want to know when they ve specified an input pattern that contains illegal characters. As noted above, MusicStringParser does not report them. 1. Using the MusicStringParser code as a guiding example, change the last test in the switch statement in parsetoken so that an exception is thrown if an unknown character is encountered. You can see from the exception raised earlier in parsetoken that you need to throw a new JFugueException with appropriate parameters. In keeping with the way the rest of the exceptions in the program are defined, you should add a definition for your new exception to the set of definitions in the class JFugueException.

2. Modify the switch statement in parsetoken to admit a colon as the first character in a token. The meaning of a colon is to repeat the action specified in the remainder of the token. That is, the remainder of the token should be performed twice. 3. For additional optional challenge, allow the addition of a colon followed by a number at the beginning of a token, and interpret the pair as a requirement to repeat the token <number> times. Be careful, because notes can be expressed using numbers also. That creates an ambiguity: Is a number near the beginning of a token a note, or a multiplier for the repeat operation (colon). Turn-in Checklist: You should turn in your answers on paper at the beginning of class on Monday, 1 Sept. For question 1, turn in your parsetoken.java code. For question 2, describe the changes you made and turn in all the code you changed. If you decide to try #3, then again, just turn in a written description of changes, and the code you actually changed.