Musical language project

Here is complete source for the Chromosphere, my project to create a machine that uses a 26-letter alphabet plus a few operators to combine them as a system of musical notation, in its initial, skeletal state. It is presently designed to run as an applet, and will offer you two buttons, one of which (“Play”) works, the other (“Stop”) is not yet enabled. If I can find a good place to host this applet, you will be able to listen if you have the ability to run Java from your web browser. The initial score is about 10 minutes long.

I could use any amount of assistance and support with this project.


/*
* Imaginary Public License version 1.0
* Copyright is only imaginary, but if you believe in copyright, then this software may be used pursuant to these license provisions:
* 1) Usage, modification and redistribution of source code are permitted so long as this section is included and maintained intact;
* 2) Distribution of binaries are permitted only when accompanied by the source code used to generate them, including this license;
* 3) Anyone using this software to perform publicly or provide output to a public network shall make their source code, including any
* input files or data used by the software, publicly available at no additional charge to anyone authorized or reasonably able to
* hear or use the output, and shall publicise its availability to them, provided that input files or data may be under a different
* license, however; and
* 4) This software is without warranty.
* Copyright (C) 2007, all other rights not specified are reserved.
*/

package chromosphere;

import java.util.*;
import java.awt.*;
import java.applet.Applet;

import com.softsynth.jsyn.*;

public class Chromosphere extends Applet {
private static final long serialVersionUID = 1L;

private Player player;

private Button playButton;
private Button stopButton;

Hashtable keyMap;

@SuppressWarnings(“deprecation”)
public static void main(String[] args) {
Chromosphere applet = new Chromosphere();
AppletFrame frame = new AppletFrame(“Chromosphere synth”, applet);
frame.resize(525, 420);
frame.show();
frame.test();
}

public void start() {
try {
Synth.startEngine(0);

keyMap = new Hashtable();
resetKeyMap();

player = new Player();
add(playButton = new Button(“Play”));
add(stopButton = new Button(“Stop”));

} catch (SynthException e) {
SynthAlert.showError(this, e);
}
}

public void stop() {
try {
Synth.stopEngine();

} catch (SynthException e) {
SynthAlert.showError(this, e);
}
}

public boolean action(Event evt, Object what) {
if (evt.target == playButton) {
playScore();

return true;
} else if (evt.target == stopButton) {
stopPlayer();

return true;
}

return false;
}

void resetKeyMap() {
keyMap.clear();

keyMap.put(‘A’, 1d / 1);
keyMap.put(‘B’, 4d / 7);
keyMap.put(‘C’, 5d / 4);
keyMap.put(‘D’, 2d / 3);
keyMap.put(‘E’, 3d / 2);
keyMap.put(‘F’, 4d / 5);
keyMap.put(‘G’, 7d / 4);
keyMap.put(‘H’, -1d / 2);
keyMap.put(‘I’, -2d / 1);
keyMap.put(‘J’, 1d / 2);
keyMap.put(‘K’, 2d / 1);
keyMap.put(‘L’, 8d / 15);
keyMap.put(‘M’, 15d / 8);
keyMap.put(‘N’, 16d / 21);
keyMap.put(‘O’, 21d / 16);
keyMap.put(‘P’, 32d / 35);
keyMap.put(‘Q’, 35d / 32);
keyMap.put(‘R’, 8d / 9);
keyMap.put(‘S’, 9d / 8);
keyMap.put(‘T’, 16d / 25);
keyMap.put(‘U’, 25d / 16);
keyMap.put(‘V’, 32d / 49);
keyMap.put(‘W’, 49d / 32);
keyMap.put(‘X’, 11d / 8);
keyMap.put(‘Y’, 13d / 8);
keyMap.put(‘Z’, 17d / 16);

keyMap.put(‘ ‘, 0d);
}

void playScore() {
String[] score = {
“*JJ *J/A:ABCDEFM: *A/K:ABCDEFM: *KA *KK”,

// Hello
“JLBDNFPAQCOEGMK AHI”,
“CANNABLOGGING AHI”,

// “Ozymandias” progression, letter order
“AB AB AC DC ED”,
“EF EF EG HG IH”,
“IJ IJ IK LK ML”,
“MN MN MO PO QP”,
“QA QA AHI”,

// Letter order
“A B C D E F G H I J K L M N O P Q AHI”,

// Denominator order
“H J D F B L N P A Q O M G C E K I AHI”,

// Reverse denominator order
“I K E C G M O Q A P N L B F D J H AHI”,

// Reverse letter order
“Q P O N M L K J I H G F E D C B A AHI”,

// Letter order with JK multipliers
“*J/A:ABCDEFGHIJKLMNOPQ: AHI”,
“*A/K:ABCDEFGHIJKLMNOPQ: *KAHI”,

// Denominator order with JK multipliers
” H J D F B L N P *J:A Q O M G C E K I: AHI”,
“*K:H J D F B L N P: A Q O M G C E K I *KAHI”,

// Reverse denominator order with JK multipliers
“*J:I K E C G M O Q A: P N L B F D J H AHI”,
” I K E C G M O Q A *K:P N L B F D J H: *KAHI”,

// Reverse letter order with JK multipliers
“*J/A:QPONMLKJIHGFEDCBA: AHI”,
“*A/K:QPONMLKJIHGFEDCBA: *KAHI”,

// Letter order with DE multipliers
“*D/A:ABCDEFGHIJKLMNOPQ: AHI”,
“*A/E:ABCDEFGHIJKLMNOPQ: *EAHI”,

// Denominator order with DE multipliers
” H J D F B L N P *D:A Q O M G C E K I: AHI”,
“*E:H J D F B L N P: A Q O M G C E K I *EAHI”,

// Reverse denominator order with DE multipliers
“*D:I K E C G M O Q A: P N L B F D J H AHI”,
” I K E C G M O Q A *E:P N L B F D J H: *EAHI”,

// Reverse letter order with DE multipliers
“*D/A:QPONMLKJIHGFEDCBA: AHI”,
“*A/E:QPONMLKJIHGFEDCBA: *EAHI”,

// Reverse letter order with JK multipliers
“*J/A:QPONMLKJIHGFEDCBA: AHI”,
“*A/K:QPONMLKJIHGFEDCBA: *KAHI”,

// Reverse denominator order with JK multipliers
“*J:I K E C G M O Q A: P N L B F D J H AHI”,
” I K E C G M O Q A *K:P N L B F D J H: *KAHI”,

// Denominator order with JK multipliers
” H J D F B L N P *J:A Q O M G C E K I: AHI”,
“*K:H J D F B L N P: A Q O M G C E K I *KAHI”,

// Letter order with JK multipliers
“*J/A:ABCDEFGHIJKLMNOPQ: AHI”,
“*A/K:ABCDEFGHIJKLMNOPQ: *KAHI”,

// Reverse letter order
“Q P O N M L K J I H G F E D C B A AHI”,

// Reverse denominator order
“I K E C G M O Q A P N L B F D J H AHI”,

// Denominator order
“H J D F B L N P A Q O M G C E K I AHI”,

// Letter order
“A B C D E F G H I J K L M N O P Q AHI”,

// “Ozymandias” progression, denominator order
“HJ HJ HD FD BF”,
“BL BL BN PN AP”,
“AQ AQ AO MO GM”,
“GC GC GE KE IK”,
“IH IH AHI”,

// “Ozymandias” progression, denominator order with FC multipliers
“*F/C:HJ HJ HD FD BF”,
” BL BL BN PN AP”,
” AQ AQ AO MO GM”,
” GC GC GE KE IK”,
” IH IH: *CAHI”,

// “Ozymandias” progression, denominator order with FC multipliers
“*F/C:HJ HJ HD FD BF”,
” BL BL BN PN AP”,
” AQ AQ AO MO GM”,
” GC GC GE KE IK”,
” IH IH: *CAHI”,

// Theme in FC
“*F/C:CANNABLOGGING: *CAHI”, /*

/* */};

boolean isPhrase = false;
double[] Mx = new double[2];
Mx[0] = 1d / 1;
Mx[1] = 1d / 1;

ArrayList compiledScore;
compiledScore = new ArrayList();
for (int i = 0; i < score.length; ++i)
for (int j = 0; j < score[i].length(); ++j) {
Character charAt = score[i].charAt(j);
switch (charAt) {
case ‘*’:
Mx[0] = keyMap.get(score[i].charAt(++j));
Mx[1] = Mx[0];
break;
case ‘/’:
Mx[1] = keyMap.get(score[i].charAt(++j));
break;
case ‘:’:
isPhrase = !isPhrase;
break;
default:
Double ratio = new Double(keyMap.get(charAt));

if (ratio >= 1d || ratio <= -1d)
ratio *= Mx[0];
else if (ratio < 1d && ratio > -1d)
ratio *= Mx[1];

if (!isPhrase) {
Mx[0] = 1d / 1;
Mx[1] = 1d / 1;
}

compiledScore.add(ratio);
}
}

player.play(compiledScore);
}

void stopPlayer() {
player.stop();
}
}

class Player {
SawtoothOscillator osc;

SynthEnvelope envData;

EnvelopePlayer envPlayer;

LineOut lineOut;

public Player() {
osc = new SawtoothOscillator();
envPlayer = new EnvelopePlayer();
lineOut = new LineOut();

envPlayer.output.connect(osc.amplitude);
double[] data = { 0.02, 1.0, // Attack to 1.0 in 0.02 sec
0.30, 0.5, // Decay to 0.5 in 0.30 sec
1.20, 0.0 // Release to 0.0 in 1.20 sec
};
envData = new SynthEnvelope(data);

osc.output.connect(0, lineOut.input, 0);
osc.output.connect(0, lineOut.input, 1);

osc.start();
envPlayer.start();
lineOut.start();
}

public void play(Double ratio) {
if (ratio == 0)
return;

if (ratio > 0) {
osc.frequency.set(420. * ratio);
envPlayer.amplitude.set(.420);
envPlayer.envelopePort.clear();
envPlayer.envelopePort.queue(envData);

} else
ratio = 0 – ratio;

Double timer = 420. / ratio;
Synth.sleepForTicks(timer.intValue());
}

public void play(ArrayList score) {
for (Iterator it = score.iterator(); it.hasNext(); )
play(it.next());
}

public void stop() {
}
}

About these ads

3 Responses to “Musical language project”

  1. ggwfung Says:

    This sounds fascinating! Many claims have been made for the Torah, among which, that it encodes a musical secret. I remember stumbling across a dusty old book in a university library many years ago, and being astonished that someone would devote years of their life in constructing such an argument.

    So this is the text-to-music project you were talking about. I’m sorry, but my technical language goes up to HTML and reaches a wall. I have mucked around with C many years ago, but I find programming a little too fiddly. Much prefer to write a poem :-)

    best of luck whig,

    ggw

  2. whig Says:

    Ggw, read just the score part if you want a sense of this language.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: