/*
* ScaleDemoServlet.java
*
* This is the web interface to the application which
* performs algorithmic composition and generates MIDI files.
* interactively from user input via html form.
*
* It performs the following for each http request:
* 1. receives and validates all inpurt fields
* 2. instatiates temperScaleDemo and passes validaed input fields
* 3. invokes temperScaleDemo class methods to create and save MIDI file
* 4. outputs html to http response including a link to the MIDI file
*
* temperScaleDemo generates a midi file of a simple ascending and
* descending equal tempered scale with a client-specified numeber
* of divisions to the octave.,
*
* This module is part of Karl Brown's MIDI programming project.
*
*/
package MidiApps;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Enumeration;
import javax.sound.midi.*;
/**
*
* @author Karl Brown
* @version 1.0
* last updated 2/16/2003
*/
public class ScaleDemoServlet extends HttpServlet {
tracer tr;
//Global variables
String namestring;
String divstring;
Integer divint;
String beatLengthString;
Long beatLengthLong;
String dirname;
String numOctavesString;
Integer numOctavesInt;
String baseMidiPitchString;
Integer baseMidiPitchInt;
String patchString;
Integer patchInt;
/** Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/** Destroys the servlet.
*/
public void destroy() {
}
/** Processes requests for both HTTP GET
and POST
methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
tr = new tracer();
java.io.PrintWriter out = response.getWriter();
tr.setPrintWriter(out);
response.setContentType("text/html");
tr.print("");
tr.print("
"); // tr.trace("instatiating equalTemperScaleDemo.."); equalTemperScaleDemo sd = new equalTemperScaleDemo(); composer c = (composer)sd; // tr.trace("executing equalTemperScaleDemo.compose()..."); sd.setNumDivisions(divint.intValue()); c.setDirectory(dirname); c.setFileName(namestring); c.setTracer(tr); //******** BEGIN HARD-CODED VALUES ******** c.setResolution(96); //******** END HARD-CODED VALUES ******** sd.setPatch((byte)patchInt.intValue()); sd.setBaseMidiPitch((byte)baseMidiPitchInt.intValue()); sd.setBeatLength((long)beatLengthLong.longValue()); sd.setNumOctaves((int)numOctavesInt.intValue()); c.compose(); // tr.trace("returned from c.compose()"); // tr.trace("executing equalTemperScaleDemo.writeMidiFile()..."); c.writeMidiFile(); // tr.trace("returned from equalTemperScaleDemo.writeMidiFile()"); String finalName = c.getFileNameFinal(); out.println("
Here is your MIDI file:
" + finalName + "
");
tr.print("Try this servlet again
");
tr.print("Midi Servlet home page");
tr.print("
");
tr.print("");
tr.print("");
out.close();
System.gc();
}
/** Handles the HTTP GET
method.
* @param request servlet request
* @param response servlet response
*/
/** Handles the HTTP GET
method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
/** Handles the HTTP POST
method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Demonstrates MIDI servlet ptogramming using equal tempered scales.";
}
}