This script is a modified version of one of the M.E.S.A. bundled scripts. It assumes M.E.S.A. is running and that an existing program and a list of samples are selected within the M.E.S.A. "Memory" window. It uses a program selected in the "Memory" window to define a series of chromatically mapped keygroups, each of which plays a sample without looping them in playback.

This was one of the first M.E.S.A. AppleScripts I "messed with" and I tried to comment the most significant lines to make it easier to understand. I have since learned to use AppleScript  "handlers" which are more modular and easy to read.

-- Revision 1.0a 10-15-98
--
-- This script is a modified version of one of the M.E.S.A. bundled scripts.
-- It assumes M.E.S.A. is running and that an existing program and a list of
-- samples are selected within the M.E.S.A. "Memory" window.
-- It uses a program selected in the "Memory" window to define a series of
-- chromatically mapped keygroups, each of which plays a sample without looping
-- them in playback. This was one of the first M.E.S.A. AppleScripts I "messed with" and I tried
-- to comment the most significant lines to make it easier to understand. I have
-- since learned to use "handlers" which are more modular and easy to read.
--
--                          Ken Loge
--                         http://dreamsteep.com


tell application "MESA II"

set s to sampler 1 -- get a reference to the sampler object

if (is online in s) then -- check if sampler is online



set sp to selected program in s -- get index of selected program

if sp is equal to 0 then error "You must select a program in the memory window"



-- get a reference to the selected program

set prog to program sp in s



-- SHOW A DIALOG ASKING FOR THE KEY ("MIDI") NUMBER OF THE FIRST ADDED KEYGROUP

set kv to 36 -- note C1 as a prompt for the user

set r to display dialog "Enter key value of 1st new keygroup:" default answer kv as text

set kv to text returned in r as integer

if kv is less than 21 or kv is greater than 127 then error "Value must be between 21 and 127"



-- FIX "TEST PROGRAM" IN KEYGROUP 1

set kg to keygroup 1 in program 1 in s

set samp to sample 1 in s

set sname to name in samp -- get the sample name

set playback type in samp to 2 -- NO LOOPING IN PLAYBACK

set sample name 1 in kg to sname -- assign the sample name in the keygroup

set lo note in kg to kv -- starting pitch

set hi note in kg to kv -- ending pitch

if kv is greater than 128 then set kv to 127 -- make sure velocity is in range

set zone 1 pitch in kg to 1 -- constant pitch

set kv to kv + 1 -- increment kv so the next keygroup is the next sample in the list



-- LOOP FOR EACH SAMPLE IN MEMORY

set numsamps to count samples in s

repeat with x from 2 to numsamps

-- get a reference to the sample

set samp to sample x in s -- samp IS THE SAMPLE ITSELF

-- if the sample is selected then add a keygroup to the program containing the sample.

if is selected in samp then

set kg to make new keygroup in prog

set sname to name in samp -- sname IS THE NAME OF THE SAMPLE

set playback type in samp to 2 -- * * * SET THE PLAYBACK TYPE TO NO LOOPS * * *

set sample name 1 in kg to sname

set lo note in kg to kv

set hi note in kg to kv

set kv to kv + 1 -- INCREMENT SO SAMPLES ARE CHROMATICALLY ARRANGED

if kv is greater than 128 then set kv to 127

set zone 1 pitch in kg to 1 -- * * *SET EACH KEYGROUP ZONE TO A CONSTANT PITCH * * *

end if

end repeat



-- redraw and update

set update in s to true

else

error "Sampler is not online. Please check the connections."

end if

end tell