Assignment 6

Due on Monday 21st April

You should submit solutions to this h/w via the cms system by 11pm on Monday. Since the only way to learn GUIs is to build them, this entire hw is devoted to this 'enjoyable' exercise. (We will develop the third question further in the next homework, integrating it with some graph drawing, but that's for later!) The first two questions are designed to help you focus on modularity of code by encouraging you to re-use your earlier code in conjunction with a freshly written GUI.

Question 1: GUI for parallel queue simulation

Consider question 1 from homework 3 (about modelling supermarket cashier queues). Write a program to give a GUI display of the behavious of these queues over time. You should keep good separation between the code handling the queues and the GIU code (hence leverage the fact that you've already written the simulation program!). You should represent the queues of 'people' as lines of biggish dots, with 'impatient' folk changing to red shortly before they skip their current queue to join the back of another one (remaining red for a short time after arrival so that we can see who went where). You should cousider how you want to display the queues changing over time so that things don't happen so quickly that we can't see anything useful. You should also institute an 'opportunity cost' associated with skipping a queue to join another by making it take some modifiable amount of time, and experiment with your program so that the overall result looks interesting.

Question 2: GUI to compare sorting speeds

Consider question 3 from homework 5 (about oarting lists using list or tree interators). Write a program to give a GUI display of a race between these various sorting techniques (selection, intertion, merge, heap). This could be modelled on the one (orignially on the Sun Java tutorial site) found here. The idea is to construct a randon array of n integers, use that to draw an initial starting set of lines, replicate this set so that there are four copies in the GUI, and then have a 'start button' which when clicked runs all four sorting techniques from your earlier code simultaneously (actually in four separate threads spawned at the same time).

Question 3: GUI and midi interaction

Consider the TextToMidi code from the code example list (as in class on Thursday). This essentially takes a string of characters and parses it so that the text-typed string gets played as a 'tune' or as chords. The object of this question is to build a GUI environment allowing both the entry of the notes for some 'music' and a way of interacting with the sound. The first step would be to build a GUI with a textfield at which the 'tune' can be entered, and a button to start the music. After that, add three more buttons to stop (end) the music, to pause-restart (allowing restart from the point it was paused, having silence during the pause), and to pauseHold-restart (similar to the previous pause-restart button, but this time having the sound (appear to) continue sounding the note or chord in process at the time of clicking this button). Next, modify your code to allow entry of 'parallel tunes' (so that two or three 'voices' can be played at the same time), and test that this works. Finally, read up on JSliders in the API and ways to do microtuning in midi, then implement (an intiail) random detuning of one of the (two or three) parallel voices, and provide a (retuning) slider for each voice so that during 'play' you can pauseHold the sound and adjust the pitch of whichever voices one wants to.

Technically, the gap between one note and the next (a semitone) would multiply the lower note's frequency by the twelfth root of 2 (so that an octave, say from A to A, which comprises twelve note gaps would exactly double the frequency) -- at least in the current day equal temperament tuning system. This semitone gap is formally divided into 100 'cents', so you might like to provide a textbox into which the user can enter some non-negative integer which could serve as the maximum permitted range of out-of-tuneness. So for example, if the user entered 50, then the de-tuned voice would have a random de-tuning of each of its notes limited in range from -50 to +50 cents, i.e., via (int)(100*Math.random() - 50).