From J Wiki
Jump to: navigation, search

Controlling the Eigenharp by calling Belcanto from J

The Eigenharp is a novel musical instrument allowing an inexhaustible range of electronically generated music to be played with maximum expressiveness.


Strictly it is a "performance controller", connecting via a USB port to a laptop computer (Macintosh or Windows) which runs the controlling software to generate and organise the sound. Whilst it can act as a MIDI instrument inputting into (say) Garageband, that is not its primary purpose. It comes with its own complete but extensible sound system including instruments and loops.

The main software is a program called EigenD, which drives all three currently available models of Eigenharp: Alpha, Tau and Pico. In what follows the entry-level model, the Pico, will be assumed, but what is said can be taken to apply to all three models of eigenharp (untested).

EigenD has been designed to be fully controllable from the physical instrument itself, allowing on-stage adjustments. The medium for this is a proprietary command language called Belcanto, the primitives of which are runs of musical notes with ASCII text equivalents. Here we consider only the ASCII form of Belcanto.

Knowledge of Belcanto is not necessary for basic usage of the eigenharp. What the average musician could expect from a typical keyboard can be setup from the laptop screen, interacting with UIs portraying recognisable mixers and synths of the past thirty years, plus a conventional sort of text-based browser (the Eigenbrowser) to select sounds, instruments, drum loops etc.

This raises the question: can the eigenharp be setup and controlled by a program written in J? Clearly it can, with the simple provision of a J word execBelcanto which issues a (text) Belcanto command to the instrument.

execBelcanto=: 3 : 0
    NB. Send Belcanto message: (y)
    NB. Mac/Unix only
z=. '/usr/pi/release-1.4.12-stable/bin/brpc ''<interpreter>'' exec ' , y
2!:1 ' &',~ z

    NB. Test expressions (EigenD must be running)...
execBelcanto 'metronome hey start'
execBelcanto 'metronome hey stop'

Let me acknowledge the advice from Geert Bevin which underpins this example.

There is another more general way of issuing a Belcanto command, namely via HTTP. This has the advantage of not needing the J program to reside on the same machine as EigenD. For a Javascript version of execBelcanto using the HTTP interface, see: [2]. This is straightforward to adapt to j701 JHS.

Vamping an accompaniment

The Eigenharp lets you record an accompaniment, then replay it under the control of the metronome button (which also controls percussion) whilst you extemporise over it.

From release 2.0.48 of EigenD, Belcanto has two new primitives: player and play, which trigger the actual playing of notes and chords, as distinct from setting up the Eigenharp to play them. The following demo app imparts some basic harmony theory, viz chord progressions. It gives you a kit of JWD buttons ("keys") which you can shuffle around to help you vamp a given tune. Clicking on a key plays the designated chord using EigenD's built-in piano instrument.


As it stands, you must use the Form Editor to do the key placement. An improved version will let you move a key in-flight by Shift+drag.

The example shown helps a keyboard novice hack out an accompaniment to Dirty Old Town, which has a rather more elaborate chord progression than the simple I-IV-V-I of much folk music (the so-called "Three-Chord-Trick"). An improved version will embed the keys in a diagram a bit like a state-transition chart. If you don't want to be clever, and given more keys, you could instead just string out a selection to be clicked in turn. My preferred way to use this is with a graphic tablet rather than a mouse.

Sheer cheating! How pathetic can you get?

NB. (c) 2012, Ian A Clark.

NB. Coded to illustrate principles with greater clarity.
NB. The code could be rewritten much more concisely,
NB. avoiding the extensive repetitions.

NB. (Orientation: Breath-tube at the bottom.)
NB. 8 4
NB. 7 3
NB. 6 2
NB. 5 1

chord=: 3 : 0
	NB. play a chord-triple on the eigenharp piano
	NB. Chords are numbered: 1 (chord I), 2 (chord ii) etc.
velocity=. 100
z=. 'note N1 with velocity V play note N2 with velocity V play note N3 with velocity V play'
z=. z rplc 'V' ; ": velocity
select. y
case. 1 do. 'N1 N2 N3'=. 1 3 5
case. 2 do. 'N1 N2 N3'=. 2 4 6
case. 3 do. 'N1 N2 N3'=. 3 5 7
case. 4 do. 'N1 N2 N3'=. 4 6 8
case. 5 do. 'N1 N2 N3'=. 2 5 7
case. 6 do. 'N1 N2 N3'=. 3 6 8
case. 7 do. 'N1 N2 N3'=. 2 4 7
case. 8 do. 'N1 N2 N3'=. 3 5 8
z=. z rplc 'N1' ; (":N1) ; 'N2' ; (":N2) ; 'N3' ; (":N3)
execBelcanto z

execBelcanto=: 3 : 0
	NB. Send Belcanto message: (y)
select. '2.0'
case. '1.4' do.
  z=. '/usr/pi/release-1.4.12-stable/bin/brpc ''<interpreter>'' exec ' , y
case. '2.0' do.
  z=. '/usr/pi/release-2.0.48-experimental/bin/brpc ''<interpreter1>'' exec ' , y
2!:1 ' &',~ z

NB. Use Form Editor to reposition the keys in FM ...

FM=: 0 : 0
pc fm;
menupop "File";
menu new "&New" "" "" "";
menu open "&Open" "" "" "";
menu exit "&Exit" "" "" "";
xywh 8 10 25 12;cc a1 button;cn "I";
xywh 32 10 25 12;cc a2 button;cn "ii";
xywh 56 10 25 12;cc a3 button;cn "iii";
xywh 80 10 25 12;cc a4 button;cn "IV";
xywh 104 10 25 12;cc a5 button;cn "V";
xywh 128 10 25 12;cc a6 button;cn "vi";
xywh 152 10 25 12;cc a7 button;cn "vii*";
xywh 176 10 25 12;cc a8 button;cn "I+";
xywh 90 109 25 12;cc b1 button;cn "I";
xywh 103 85 25 12;cc b2 button;cn "ii";
xywh 56 20 25 12;cc b3 button;cn "iii";
xywh 80 20 25 12;cc b4 button;cn "IV";
xywh 104 20 25 12;cc b5 button;cn "V";
xywh 69 59 25 12;cc b6 button;cn "vi";
xywh 154 101 25 12;cc b7 button;cn "vii*";
xywh 90 97 25 12;cc b8 button;cn "I+";
xywh 42 72 25 12;cc c1 button;cn "I";
xywh 135 101 25 12;cc c2 button;cn "ii";
xywh 69 85 25 12;cc c3 button;cn "iii";
xywh 69 72 25 12;cc c4 button;cn "IV";
xywh 103 71 25 12;cc c5 button;cn "V";
xywh 111 101 25 12;cc c6 button;cn "vi";
xywh 151 23 25 12;cc c7 button;cn "vii*";
xywh 42 59 25 12;cc c8 button;cn "I+";
pas 6 6;pcenter;
rem form end;

start=: 3 : 0
wd FM
NB. initialize form here
wd 'pshow;'

fm_close=: 3 : 0
wd :: 0: 'psel fm; pclose'

fm_a1_button=: chord bind 1
fm_a2_button=: chord bind 2
fm_a3_button=: chord bind 3
fm_a4_button=: chord bind 4
fm_a5_button=: chord bind 5
fm_a6_button=: chord bind 6
fm_a7_button=: chord bind 7
fm_a8_button=: chord bind 8

fm_b1_button=: chord bind 1
fm_b2_button=: chord bind 2
fm_b3_button=: chord bind 3
fm_b4_button=: chord bind 4
fm_b5_button=: chord bind 5
fm_b6_button=: chord bind 6
fm_b7_button=: chord bind 7
fm_b8_button=: chord bind 8

fm_c1_button=: chord bind 1
fm_c2_button=: chord bind 2
fm_c3_button=: chord bind 3
fm_c4_button=: chord bind 4
fm_c5_button=: chord bind 5
fm_c6_button=: chord bind 6
fm_c7_button=: chord bind 7
fm_c8_button=: chord bind 8


smoutput 0 : 0
	TEST: enter:
execBelcanto 'metronome hey start'
execBelcanto 'metronome hey stop'
chord 1
chord 2

Contains an extended version of execBelcanto to run with release 2.0.48

Running the code example

To run this mini-app you need to install J602 first ('s free).

Then create a new temporary code window (Menu: File > New ijs) and copy/paste the above code sample into it. Then run it by: Menu: Run > Window (making sure the window to-be-run is first selected).

For this app to work, you also need to have run the following Belcanto script (named player_create_3.txt) as part of your instrument set-up:

	Create a player to play synth 3 (piano) notes
	To be placed in: ~/Library/Eigenlabs/Scripts/player_create_3.txt
	Needs eigenD release-2.0.48-experimental -or higher.
	player create
        player key to sampler rig 3 key connect
        player pressure to sampler rig 3 pressure connect