more newbie scripting help
Hi again,
Trying to learn how multi-dimensional arrays work. The following script seems to work fine sometimes but causes "access violation" errors at other times. Sometimes crashes HH. Can anyone tell me if the script is "wrong" and in what way(s)? Thanks!
//////////////////////////
// 2 Dimensional MIDI array sandbox
/////////////////////////
// parameters declaration
var MIDI_in : TParameter;
var chordCount : TParameter; // count of chords in memory
var cCount : integer; // total number of recorded chords
// initialisation : create parameters
procedure init;
begin
MIDI_in := CreateParam('MIDI_in',ptMidi);
chordCount := CreateParam('chordCount',ptDataField);
SetIsOutPut(MIDI_in,false);
SetIsInput(chordCount,false);
SetFormat(chordCount,'%.1f');
cCount := 0;
end;
// Global variables
var i : integer;
var nCount : integer; // count of notes in current chord
var nbOfMidi : integer; // length of received MIDI array
var Mdat : TMidi; // single message of received MIDI data
//var tnMdat : array of TMidi; // temporary array of MIDI notes
type tnMdat = array of TMidi; // temporary array of MIDI notes
var chordsMdat : array of tnMdat; // final array of MIDI chords
Procedure Callback(N:integer);
begin
case n of
0: begin // activity on MIDI input
nbOfMidi := GetLength(MIDI_in); // get the number of incoming midi codes
if nbOfMidi > 0 then
begin
for i := 0 to nbOfMidi-1 do // loop for all input codes, for polyphonic data (chords)
begin
GetMidiArrayValue(MIDI_in,i,Mdat); // get each code
if Mdat.msg = 144 then // if note on
begin
nCount := nCount+1; // inc note on count
setValue(chordCount,nCount);
SetArrayLength(chordsMdat,cCount); // set to chord count
chordsMdat[cCount,i] := Mdat;
itrace(chordsMdat[cCount,i].data1);
itrace(cCount);
setValue(chordCount,nCount);
end;
if Mdat.msg = 128 then // if note off
begin
nCount := nCount-1; // dec note count
if nCount = 0 then // if all notes are off
begin
cCount := cCount+1; // inc chord count
end;
end;
end;
end;
end;
end;
end;
Trying to learn how multi-dimensional arrays work. The following script seems to work fine sometimes but causes "access violation" errors at other times. Sometimes crashes HH. Can anyone tell me if the script is "wrong" and in what way(s)? Thanks!
//////////////////////////
// 2 Dimensional MIDI array sandbox
/////////////////////////
// parameters declaration
var MIDI_in : TParameter;
var chordCount : TParameter; // count of chords in memory
var cCount : integer; // total number of recorded chords
// initialisation : create parameters
procedure init;
begin
MIDI_in := CreateParam('MIDI_in',ptMidi);
chordCount := CreateParam('chordCount',ptDataField);
SetIsOutPut(MIDI_in,false);
SetIsInput(chordCount,false);
SetFormat(chordCount,'%.1f');
cCount := 0;
end;
// Global variables
var i : integer;
var nCount : integer; // count of notes in current chord
var nbOfMidi : integer; // length of received MIDI array
var Mdat : TMidi; // single message of received MIDI data
//var tnMdat : array of TMidi; // temporary array of MIDI notes
type tnMdat = array of TMidi; // temporary array of MIDI notes
var chordsMdat : array of tnMdat; // final array of MIDI chords
Procedure Callback(N:integer);
begin
case n of
0: begin // activity on MIDI input
nbOfMidi := GetLength(MIDI_in); // get the number of incoming midi codes
if nbOfMidi > 0 then
begin
for i := 0 to nbOfMidi-1 do // loop for all input codes, for polyphonic data (chords)
begin
GetMidiArrayValue(MIDI_in,i,Mdat); // get each code
if Mdat.msg = 144 then // if note on
begin
nCount := nCount+1; // inc note on count
setValue(chordCount,nCount);
SetArrayLength(chordsMdat,cCount); // set to chord count
chordsMdat[cCount,i] := Mdat;
itrace(chordsMdat[cCount,i].data1);
itrace(cCount);
setValue(chordCount,nCount);
end;
if Mdat.msg = 128 then // if note off
begin
nCount := nCount-1; // dec note count
if nCount = 0 then // if all notes are off
begin
cCount := cCount+1; // inc chord count
end;
end;
end;
end;
end;
end;
end;
Regards,
Scott
Scott
I think it is because you are setting the array length of chordsMdat, but the length of tnMdat is never set. In my experience with multidimensional arrays, usually at least the "first dimension" of the array has a defined length, but you could play arround with setting the length of tnMdat before setting the length of chordsMdat and see if ol Pascal can cope.
I've also never seen the multiDimension[x,y] syntax before, I've only ever used multiDimension[x][y]. But if it compiles then I guess Pascal understands
Is the idea of the script to collect the number of notes in a chord and set them to an array? Because I think you can just use a single dimension array of tMidi for that purpose.
Also, oli_lab used a number in his callback case statement, but you can definitely just use the parameter variable as you were doing in your first example (from the other thread). For me scripting would be unusable if I had to keep track of what param has what number!
I've also never seen the multiDimension[x,y] syntax before, I've only ever used multiDimension[x][y]. But if it compiles then I guess Pascal understands
Is the idea of the script to collect the number of notes in a chord and set them to an array? Because I think you can just use a single dimension array of tMidi for that purpose.
Also, oli_lab used a number in his callback case statement, but you can definitely just use the parameter variable as you were doing in your first example (from the other thread). For me scripting would be unusable if I had to keep track of what param has what number!
Writing my Pattern Store script I learned a lot about how to handle arrays. In a word: delicately
The best example may be the 'tSteps' and 'stepBank'. Giving these strict values through constants gives Usine the chance to anticipate the maximum impact of the script. Try giving yourself a maximum polyphony (which could even be pretty big without having a negative impact I think).
I dynamically set the length of a patternBank array, but that doesn't end up doing anything in the script. I do remember having to move the setting of that length into the 'init' procedure. Something about constants and arithmetic outside of procedures I think.
But using constants allows for quick reconfigurability. This script only stores 4 pattern sets, at 8 patterns a set. But that can be quickly recomposed.
The best example may be the 'tSteps' and 'stepBank'. Giving these strict values through constants gives Usine the chance to anticipate the maximum impact of the script. Try giving yourself a maximum polyphony (which could even be pretty big without having a negative impact I think).
I dynamically set the length of a patternBank array, but that doesn't end up doing anything in the script. I do remember having to move the setting of that length into the 'init' procedure. Something about constants and arithmetic outside of procedures I think.
But using constants allows for quick reconfigurability. This script only stores 4 pattern sets, at 8 patterns a set. But that can be quickly recomposed.
Thanks very much @ceasless. It seems pre-dimensioning tnMdat did the trick. I also moved it to the parameters declaration section for good measure.
This little project is on its way to becoming a "chord palette" which records chords and allows them to be re-played using a single trigger and an ordinal value. (I'm a drummer in a world of keyboardists.) I intend to use monome/arc and iPad/Lemur as control interfaces.
Your pattern store script is a lovely bit of code. Having looked at it for only 30 seconds, is it a grid-type sequencer?
This little project is on its way to becoming a "chord palette" which records chords and allows them to be re-played using a single trigger and an ordinal value. (I'm a drummer in a world of keyboardists.) I intend to use monome/arc and iPad/Lemur as control interfaces.
Your pattern store script is a lovely bit of code. Having looked at it for only 30 seconds, is it a grid-type sequencer?
Regards,
Scott
Scott
Indeed, it's maybe the single most important piece of my Sequins 6 add-on.
You can read about it here, the documentation is for a slightly older, 4-lane version, but it's basically the same. You can use the 'sequins core' patch in any polyphony amount you want.
Let me know if you enjoy it!
[Edit: There will be some improvements to the engine, such as adjustable smoothing of the step sequencer lanes and external control for the loading of patterns. Right now it needs a step counter input and loads a new pattern on the 32nd step. It will be more useful for patching if that logic exists outside of the script itself.]
You can read about it here, the documentation is for a slightly older, 4-lane version, but it's basically the same. You can use the 'sequins core' patch in any polyphony amount you want.
Let me know if you enjoy it!
[Edit: There will be some improvements to the engine, such as adjustable smoothing of the step sequencer lanes and external control for the loading of patterns. Right now it needs a step counter input and loads a new pattern on the 32nd step. It will be more useful for patching if that logic exists outside of the script itself.]
I'll have a look at Sequins this weekend. Looks pretty cool...
Regards,
Scott
Scott
Johnny do any of your Soundcloud postings use Sequins?
Regards,
Scott
Scott
Of those tracks, only the Stolen Knoxlies rough demo uses Sequins. I had that driving my LXR. Much nicer for dealing with velocity than the (very powerful but) tedious step locks in the hardware, but the current Sequins was patched with driving Battery and other VSTs in mind (EXD-80 is a must try if you are running a Windows somewhere, so many good params to modulate).
So currently MIDI cc params need to be wired by hand using a multiplier and a create midi patch. I plan to make a new version that addresses that.
It's also going to get rigged up to the Usine Push patches at some point
So currently MIDI cc params need to be wired by hand using a multiplier and a create midi patch. I plan to make a new version that addresses that.
It's also going to get rigged up to the Usine Push patches at some point
Speaking of soundcloud, if you are ahonoe over there then I like your stuff.
How is your chord manager coming along?
How is your chord manager coming along?
Yes that's also my handle on soundcloud. Glad you like it.
Progress is slow on my chord pad. I'm trying to figure out how to delete entries from array. I can't seem to find a Pascal equivalent of deletearrayitem(). Any suggestions?
Progress is slow on my chord pad. I'm trying to figure out how to delete entries from array. I can't seem to find a Pascal equivalent of deletearrayitem(). Any suggestions?
Regards,
Scott
Scott
I would try using another array and swapping between the two, leaving out whichever elements you don't want to keep.
Did that make any sense? 
Having programmed primarily in dynamic languages, it took some time to wrap my head around the much more... stoic? .. nature of Pascal. (Still crossing fingers for an embedded Lua interpreter, hopefully it happens at some point or they might fall off.)
What's happening musically at the moment you want to delete from the array?
Having programmed primarily in dynamic languages, it took some time to wrap my head around the much more... stoic? .. nature of Pascal. (Still crossing fingers for an embedded Lua interpreter, hopefully it happens at some point or they might fall off.)
What's happening musically at the moment you want to delete from the array?
Actually your suggestion for deleting array elements is so reasonable that it scares me that it hadn't occurred to me. :0) I do find Pascal to be a bit cumbersome and rigid as a scripting language. Lua would be an awesome alternative.
My chord pad project is really designed to simplify performance for me. It memorizes chords that I play on my keyboard. It then lets me assign them, delete them and play them from Lemur buttons on my iPad. With your help I can now build and play my array of chords. I'm looking to add the delete and reassign functions.
My chord pad project is really designed to simplify performance for me. It memorizes chords that I play on my keyboard. It then lets me assign them, delete them and play them from Lemur buttons on my iPad. With your help I can now build and play my array of chords. I'm looking to add the delete and reassign functions.
Regards,
Scott
Scott
Who is online
Users browsing this forum: No registered users and 28 guests
