*** K1ed.exe   -  The Kawai K1 envelope editor software notes   ****
 
Alan Probandt   Dec 2003       alan_probandt@yahoo.com


** Introduction

	This program was written for editing the voices of the Kawai K1 synthesizer family (K1, K1m, K1r)
with an IBM PC.  The MIDI interface is a Roland MPU-401 type that is used in UART mode.  There 
is no interrupt used: all the reads and writes to the MIDI interface are done by polling the I/O ports 
of the card until they are ready to send or receive data from the PC.

	Use the command line argument 'demo' to run the program without having a K1synth connected.
Example:  c:\K1\k1ed.exe demo   <enter>    
 	You can change the default MIDI port from 0x330-331 by putting a different port address in hex
as the command line argument.  For example, to avoid conflicting with the standard MIDI port
found on the PC's joystick connector, set your MPU401 MIDI port to 0x300 and use the command:
    c:\K1\k1ed.exe 0x300 <enter>  (be sure to include the 0x characters before the hex number)
    
	This program only works with Windows 98 and earlier (Win95, Win3.1, and DOS).  
Windows 2000 or XP forbids you from writing directly to the I/O ports; a requirement of this program.
If you are using Windows XP, ME, 2000 Professional, or NT, then I suggest downloading a 
Windows 98 start-up diskette from the web.  
	Set your BIOS start-up to start booting from the floppy drive, then the hard disk.  When you
want to run this program, put the Windows startup diskette in the floppy drive with the power off and
start the PC.  You will get a command line prompt from which you can run this program.  Be sure to 
have a mouse driver program like 'mouse.exe' in order to use your mouse.  When finished, remove the
diskette and reboot your PC.  The advanced Windows OS will start without problems.
	Another approach would be to get a USB MIDI interface, or rewrite the MIDI I/O sections so that
they access the PC soundcard's joystick connector MIDI port using API calls.  I don't know how to
do this.  Or use a Visual Basic or Visual C++ DLL driver that enables direct reading and writing to 
the MIDI ports.  My attempts to do this resulted in intermittent operation and poor results.  I abandoned
that approach for the old MPU401-Win98-TurboC method.
	Another method that will work is to get a Yamaha or Roland Tone module from the mid-1990's 
that has a direct serial port interface from the synth to the PC.  Then you can write standard serial 
38.4K baud code in Visual Basic or C that gets translated into MIDI in and MIDI out by the tone 
module.  Any data sent to the tone module in serial format get converted to MIDI and retransmitted 
out of the tone module's MIDI OUT.  MIDI IN goes to the PC through the tone mods serial cable 
connection.  The Yamaha CBX-T3 and TG-100 both work this way, have excellent (but non-editable) 
GM ROM voice sets, and sell on EBay for about $45.



** Using the Editor  ---   Command Overview
                              
   level                      
              /\  <--- click on bend point tip to edit envelope display and values              
             /  \                           
  	    /    \____ sustain              
           /              \         
          /                \        
delay /                  \       
    ---/                    \      
  -|-----------------|----     
 On  	attack      off        
      	  decay   release  
 
 	   To change the source envelopes, place the mouse cursor on a point where the
envelope line segments bend and click.  Moving the mouse will 'rubber-band' the envelope.
Clicking again will send sys-ex messages for adjusted parameters to the K1.  

	The parameters to the left of the click point are the ones changed.  For example, 
clicking on the level peak and rubber banding will change the attack and the peak level.  
Clicking at the beginning on a envelope with no delay will allow changing the delay value; 
the cursor will move only on the X axis. After the second click, the envelope gets redrawn,
the white box values are updated with values that match the new envelope, and these new 
values are sent to the K1 as a series of sys-ex change-parameter messages.

	The release value is changed by clicking on the end point of the sustain. The new release value
is the slope (the X length) of the rubber-banded line segment between the right sustain and the end.

	It seems that the volume will never go above the Level setting.  If you set the Level at 20 
and the Sustain at 80, the sound volume will rise to 20 and stay there until the Note-Off message.

	To change the non-envelope parameters such as volume, source voice, ring mod, ect. , place the
mouse cursor on the blue number in the white displayed box and click.  Move the mouse up or down 
to change the displayed value.  Click again to freeze the new value and send it to the K1.

	Clicking on the source patch names in the upper right will change the voice patch name
as the mouse is moved up or down.  A second click with change the source voice in the K1 to
its new selection.  Click on the large type voice name to enter a new set of characters for the 
voice name.  Press <enter> to bring back the mouse cursor.  
	The exception is the <Mute> parameters.  They don't work until the "Update" menu
item is clicked.  And value 1 turns the source off, value 0 turns it back on.

	 Pressing the letter-number keys will play notes like a piano.   The lowest notes
start with letter 'Q' and go to '\'; they continue with 'z'.  The highest notes are by the
<enter> key.   Rows QWERTY and ZXCV are white piano keys; the number row and
ASDF row are black piano keys, except 'a' which is note B2.

        These notes are sent to the synthesizer with Note-On commands.  No Note-Off 
command is ever sent so the notes played will sound until the space bar is pressed, which
sends the MIDI control command message for All Notes Off  (b0 7b 00h).  Or click the
mouse pointer on any non-active place on the display screen to send an All_Notes_Off message.
All MIDI commands are sent and received on MIDI channel 1, for example:
pressing the letter 'z' on keyboard sends Note_On for middle C (90h 3ch 60h).

	After changing the voice parameters to customize the sound, click on the "Update"
selection on the menu bar in the top right of the screen.  This copies all of the new parameters
to the internal voice memory of the K1.   

	Select a new voice by using the function keys along with the 'meta' keys (Control, Alt, and 
Shift). F1 to F8 selects voice A-1 to A8.  Shift+F1 to Shift+F8 selects B1 to B8,  Control+F1 to 
Cntrl+F8 selects C1 to C8, and Alt+F1 to Alt+F8 selects voice D1 to D8.

	As far as I can tell, the K1 copies all of the individual voice parameters from the internal 
memory to a temporary voice buffer.  The actual K1sound is formed from the values in this 
temporary play-voice buffer.  Changing an individual parameter by mouse sends a K1 change-
parameter sys-ex message.  This changes the value only in the temp voice buffer and not in 
the main voice storage memory.  Only when the entire set of 87 parameters and correct checksum 
is sent to the K1 [as a Single-Voice type of sys-ex message] does the set of changed parameters 
actually get written to the K1's internal voice storage locations.  Clicking on 'Update' (or right click -
which is supposed to work also) sends the 87 params as a new single voice sys-ex message.

	The K1 is unusual because it is the only synth that I've ever seen that stores its internal voice set
only in internal battery-backup RAM.  Once you change the voice there, it stay changed and there is no
way to get the original factory voice back.  All other synths store their factory-preset voices
in ROM where they can't be altered.  Most other synths, like the K1, also have battery non-volatile 
RAM for storing the user-edited voices after the power has been turned off.  
	
	In other words, if you make many changes to a voice and don't click on the "Update"
command, then all of the changes will be lost when you select a new voice.  If you do click on "Update"
then you have overwritten the voice that you originally started with.

	The library functions of the program are currently all but non-existent.  Clicking on 'library'
will bring up a prompt for a file name.  In the file will be saved the 87 parameters of the current voice.
A program called 'File2SN.exe' and its source is included.  This program will write a sys-ex file 
from the PC disk to the synth.  I use it to load sound banks into the K1.

	To exit the program, use Alt-X or click on the 'Quit' menu in the upper right corner.

***** Compiling the source code

	The program is written in Turbo C because I don't know how to program for the API 
multimedia MIDI functions in Windows.  If you know how to do this then please send me an
e-mail with some code examples and I will rewrite the program in Visual C++ or Visual Basic
for use with the standard PC joystick-connector MIDI port.   In the meantime I have adapted 
an editor program written twelve years ago for the Yamaha TX-81Z to the Kawai K1.  I was
more impatient to hear the range of new sounds in the Kawai K1 than to learn a whole new type
of programming.
	The included open source code for this program is written in Turbo C (which is now available
for free on the Borland web site).  It has been compiled using LARGE memory model, no floating 
point, stack warning enabled, and graphics library enabled under Turbo C 2.01.  
	The recommended directory (folder) for the source is  "C:\K1".  The project file and
source code's include files point to this folder name.  Set the output directory in Turbo C to this 
folder also (Alt-O, D, Output Dir => c:\k1.  Save these changes with Alt-O, Save Config
file, enter for "C:\TC\TCCONFIG.TC", and 'Y' for yes.
	Unselect the ReadOnly file attribute for the source files if it is set for any of them.  This 
attribute is usually set when files are loaded from a CD.  Compile the source code with the 
K1ed.prj file supplied.  In Turbo C,  use Alt-P, select Project Name and enter the full path for 
the project file K1ed.PRJ.  Save the changes with Alt-O, Save Config file, enter for 
"C:\TC\TCCONFIG.TC", and 'Y' for yes.   Use Alt-C and 'B' to compile the entire program 
to an EXE file.  Then use Control-F9 to run the program from within Turbo C or exit Turbo C
and run K1ed.exe from the command line. 
	For more info on Turbo C, try the local public library as they often have older computer 
books still on the shelves.  You are unlikely to find anything in a bookstore about this old topic.
