…
sorry I was on the way back home… But Peter was here.
This is what I propose you, I compile it successfully and call Edit function from App_Background without any Hardfault, I verify reset and copy subfunction by SendDebugMessage… All is fine.
your whole modified project: http://www.midibox.org/dokuwiki/lib/exe/fetch.php?media=phatline:seq-melody-footboard_copie.zip
in details:
first better to use same struct as clipboard:
//Card-Clip-Container store\_t loop[8]; store\_t loop\_copy; //instead of // u16 SEQ\_copy[512][8] = {{}}; //Copy actual Track into ClipboardBuffer // u16 MSQ\_copy[512] = {}; //Copy actual Track into ClipboardBuffer // u16 PB\_copy [512] = {}; //Copy actual Track into ClipboardBuffer // u16 tact\_info\_copy[32] = {}; //Copy bpm, loop length, tact and so on
better using bits for edit flags, you will understand why after:
// char edit[4] = {1,1,1,1}; //PB, SEQ, MSQ, Beatstructure, Edit Flags for copy paste clear u8 edit = 0xff; //PB, SEQ, MSQ, Beatstructure, Edit Flags for copy paste clear
to initialise your tracks in APP_Init:
//initalize 8 Tracks with standard values u8 a; edit= 0x0f; for ( a=0; a\<8; a++ )Edit\_Clip(a, 0, 0);
This is what I did to check edit function at startup:
void APP\_Background(void){ #ifdef APP\_EDIT\_TEST edit= 0x0f; Edit\_Clip(0, 0, 1); u16 c, x; for( c=0; c\<512; c++ ) { MIOS32\_MIDI\_SendDebugMessage("PB: %d: %d to %d.", c, loop[0].PB[c] ,loop\_copy.PB[c]); for(x=0; x\<8; x++)MIOS32\_MIDI\_SendDebugMessage("SEQ: %d: %d to %d.", c, loop[0].SEQ[c][x] ,loop\_copy.SEQ[c][x]); MIOS32\_MIDI\_SendDebugMessage("MSQ: %d: %d to %d.", c, loop[0].MSQ[c] ,loop\_copy.MSQ[c]); MIOS32\_MIDI\_SendDebugMessage("leader: %d: %d to %d.", c, loop[0].leader,loop\_copy.leader); MIOS32\_MIDI\_SendDebugMessage("virgin: %d: %d to %d.", c, loop[0].virgin,loop\_copy.virgin); MIOS32\_MIDI\_SendDebugMessage("length: %d: %d to %d.", c, loop[0].length, loop\_copy.length); MIOS32\_MIDI\_SendDebugMessage("decay: %d: %d to %d.", c, loop[0].decay, loop\_copy.decay); MIOS32\_MIDI\_SendDebugMessage("rythm: %d: %d to %d.", c, loop[0].rythm, loop\_copy.rythm); MIOS32\_MIDI\_SendDebugMessage("bpm: %d: %d to %d.", c, loop[0].bpm, loop\_copy.bpm); } #endif // endless loop while( 1 ) {} }
Result:
Working with edit bits flags, You have to verify this cause I haven’t got the necessary hardware.
-
In APP_SRIO_ServicePrepare
MIOS32_DOUT_PinSet( 56, edit & 0x01); MIOS32_DOUT_PinSet( 57, (edit>>1) & 1); MIOS32_DOUT_PinSet( 58, (edit>>2) & 1); MIOS32_DOUT_PinSet( 59, (edit>>1) & 1); //instead of // MIOS32_DOUT_PinSet( 56, edit[0]); // MIOS32_DOUT_PinSet( 57, edit[1]); // MIOS32_DOUT_PinSet( 58, edit[2]); // MIOS32_DOUT_PinSet( 59, edit[3]);
-
In APP_DIN_NotifyToggle
case8: edit ^= (1<<0);break;// Act on: PB case9: edit ^= (1<<1);break;// Act on: SEQ case 10: edit ^= (1<<2);break;// Act on: MSQ-CC case 11: edit ^= (1<<3);break;// Act on: Beat structure like Loop Length BPM and so on //instead of // case 8: edit[0] =! edit[0]; break; // Act on: PB // case 9: edit[1] =! edit[1]; break; // Act on: SEQ // case 10: edit[2] =! edit[2]; break; // Act on: MSQ-CC // case 11: edit[3] =! edit[3]; break; // Act on: Beat structure like Loop Length BPM and so on
Now this is your modified edit function:
Note: better to remove clip variable if you do not use it
// E D I T C L I P D A T A static void Edit\_Clip(u8 track, u16 clip, u16 job){ // clip is not used in this procedure better to remove it ;) switch(job) { // Reset(Clear) case 0: if(edit & (1\<\<0))wmemset(loop[track].PB, (u32)((8192\<\<16) + 8192), (sizeof (loop[track].PB))/4); // reset Pitch Bend if(edit & (1\<\<1))memset(loop[track].SEQ, 0, sizeof loop[track].SEQ);// reset Note if(edit & (1\<\<2))memset(loop[track].MSQ, 0, sizeof loop[track].MSQ);// reset Control Change if(edit & (1\<\<3)){// reset track parameters loop[track].leader = 0; loop[track].virgin = 1; loop[track].length = 1; loop[track].decay = 60; //maximal 256 since we use u8 integer type loop[track].rythm = 4; loop[track].bpm = 120; } break; // Copy case 1: if(edit & 0x0f)memcpy(&loop\_copy, &loop[track], sizeof loop\_copy);// copy full track else{ if(edit & (1\<\<0))memcpy(loop\_copy.PB, loop[track].PB, sizeof loop\_copy.PB);// copy Pitch Bend if(edit & (1\<\<1))memcpy(loop\_copy.SEQ, loop[track].SEQ, sizeof loop\_copy.SEQ);// copy Note if(edit & (1\<\<2))memcpy(loop\_copy.MSQ, loop[track].MSQ, sizeof loop\_copy.MSQ);// copy Control Change if(edit & (1\<\<3)){// copy track parameters loop\_copy.leader = loop[track].leader; loop\_copy.virgin = loop[track].virgin; loop\_copy.length = loop[track].length; loop\_copy.decay = loop[track].decay; loop\_copy.rythm = loop[track].rythm; loop\_copy.bpm = loop[track].bpm; } } break; // Paste case 2: if(edit & 0x0f)memcpy(&loop[track], &loop\_copy, sizeof loop\_copy);// paste full track else{ if(edit & (1\<\<0))memcpy(loop[track].PB, loop\_copy.PB, sizeof loop[track].PB);// paste Pitch Bend if(edit & (1\<\<1))memcpy(loop[track].SEQ, loop\_copy.SEQ, sizeof loop[track].SEQ);// paste Note if(edit & (1\<\<2))memcpy(loop[track].MSQ, loop\_copy.MSQ, sizeof loop[track].MSQ);// paste Control Change if(edit & (1\<\<3)){// paste track parameters loop[track].leader = loop\_copy.leader; loop[track].virgin = loop\_copy.virgin; loop[track].length = loop\_copy.length; loop[track].decay = loop\_copy.decay; loop[track].rythm = loop\_copy.rythm; loop[track].bpm = loop\_copy.bpm; } } break; } }
This must be faster, as you can see, if edit has bit 0 to 3 @1 then the whole track will be copied or pasted in one unique memcpy 
Voilà!