Csound Csound-dev Csound-tekno Search About

[Csnd] problems /bug with ctrlselect

Date2024-10-10 11:21
FromPhilipp Neumann <0000119f78f3a4f9-dmarc-request@LISTSERV.HEANET.IE>
Subject[Csnd] problems /bug with ctrlselect
Hello everybody,

i think i found a bug in the ctrlpreset, ctrlselect and ctrlsave opcodes.

i created a .csd for controlling presets for a midi controller (encoder).
i can save presets like i want, to a .txt file. in the .txt file everything looks fine. so i guess ctrlsave and ctrlpreset are fine.
but the problem starts when i recall presets.

to describe the problem, let’s assume i have cc 1 - 4.
i save a preset-1 with
cc1: 127
cc2: 0
cc3: 0
cc4: 0

i save preset-2 with
cc1: 0
cc2: 127
cc3: 0
cc4: 0

now i recall preset-1 and everything is like expected.
now i change e.g. cc4 manually to 127.
so the setting is
cc1: 127
cc2: 0
cc3: 0
cc4: 127

now i want to recall preset-2
and i get
cc1: 0
cc2: 127
cc3: 0
cc4: stays 127!!! but should be 0, like i the preset i saved.

here is my .csd. maybe i also did a mistake, but i think i didn’t.

/* opcodes fore midi presets:
ctrlselect: loads a preset of values via a tag
ctrlpreset: defines a preset with a tag
ctrlprintpresets: Prints the current collection of presets for MIDI
  controllers of a txt file
*/

// macro for updating a midi controller
;; gets the current cc of a MIDI controller
;; and sends it to itself
;; can be used to init a controller with values or update a controller
;; after a preset call
#define UPDATE_CC(Chn'CC)
#
i$CC chanctrl $Chn, $CC, 0, 127
outic $Chn, $CC, i$CC, 0, 127
#

instr initToZero_faderfoxec4
  // init all faderfox cc to 0
  ctrlinit(1,
    0,0, 1,0, 2,0, 3,0, 4,0, 5,0, 6,0, 7,0, 8,0, 9,0, 10,0, 11,0, 
    12,0, 13,0, 14,0, 15,0)
  
  $UPDATE_CC(1'0)
  $UPDATE_CC(1'1)
  $UPDATE_CC(1'2)
  $UPDATE_CC(1'3)
  $UPDATE_CC(1'4)
  $UPDATE_CC(1'5)
  $UPDATE_CC(1'6)
  $UPDATE_CC(1'7)
  $UPDATE_CC(1'8)
  $UPDATE_CC(1'9)
  $UPDATE_CC(1'10)
  $UPDATE_CC(1'11)
  $UPDATE_CC(1'12)
  $UPDATE_CC(1'13)
  $UPDATE_CC(1'14)
  $UPDATE_CC(1'15)

  turnoff 
endin
schedule("initToZero_faderfoxec4", 0, 1) 

instr presets_faderfoxec4
  #include "faderfox-midi-presets.txt"
  gkMidiData[] ctrlsave 1,\
    0,1,2,3,4,5,6,7,8,9,10,\
    11,12,13,14,15
  
  // selecting preset mode, saving oder calling presets
  ;; 's' = 115 for save mode
  ;; 'c' = 99 for call mode
  iSave = 115
  iCall = 99

  kChar,kDown sensekey
  ;;  printks2 "kChar: %d\n", kChar
  // save trig
  kSaveTrig init 0  
  if kChar == iSave && kDown == 1 then
    kSaveTrig = 1
  else
    kSaveTrig = 0
  endif
  
  // call trig
  kCallTrig init 0
  if kChar == iCall && kDown == 1 then
    kCallTrig = 1
  else
    kCallTrig = 0
  endif

  if kSaveTrig == 1 then
    event "i", "print_save", 0, 1
  endif
  if kCallTrig == 1 then
    event "i", "print_call", 0, 1
  endif

  // save or call mode
  kModeSelect init iCall
  if kChar != -1 && kDown == 1 then
    kMode = kChar
  else
    kMode = kModeSelect
  endif
  kModeSelect = (kMode == iSave) ? iSave : kModeSelect
  kModeSelect = (kMode == iCall) ? iCall : kModeSelect

  // choosing preset number
  kPresetNum init 0
  kPresetNum = (kChar >= 49 && kChar <= 57 ? (kChar - 48) : kPresetNum)
  kPresetNum = (kChar == 48 ? 0 : kPresetNum)
  printks2 "Preset Number: %d\n",kPresetNum
  
  // Save preset
  kChanged changed kPresetNum
  printks2 "kChanged: %d\n", kChanged
  if (kModeSelect == iSave) && (kChanged == 1) then
    event "i", "savePreset_faderfoxec4", 0, 1, kPresetNum
  endif
    
  // call preset
  if (kModeSelect == iCall) && (kChanged == 1) then
    event "i", "callPreset_faderfoxec4", 0, 1, kPresetNum
  endif
endin
schedule("presets_faderfoxec4", 0, 6000000)

instr print_save
  printf "\nPRESET-SAVE-MODE\n",1
  turnoff
endin

instr print_call
  printf "\nPRESET-CALL-MODE\n",1
  turnoff
endin

instr savePreset_faderfoxec4
  printf "\nIS-SAVING PRESET: %d\n",1, p4
  kPreset ctrlpreset p4, gkMidiData
  ctrlprintpresets "faderfox-midi-presets.txt"
  turnoff
endin

instr callPreset_faderfoxec4
  printf "\nIS-CALLING PRESET: %d\n",1, p4
  ctrlselect p4
  event "i", "updateCC_faderfoxec4", 0, 1
  turnoff
endin

instr updateCC_faderfoxec4
  $UPDATE_CC(1'0)
  $UPDATE_CC(1'1)
  $UPDATE_CC(1'2)
  $UPDATE_CC(1'3)
  $UPDATE_CC(1'4)
  $UPDATE_CC(1'5)
  $UPDATE_CC(1'6)
  $UPDATE_CC(1'7)
  $UPDATE_CC(1'8)
  $UPDATE_CC(1'9)
  $UPDATE_CC(1'10)
  $UPDATE_CC(1'11)
  $UPDATE_CC(1'12)
  $UPDATE_CC(1'13)
  $UPDATE_CC(1'14)
  $UPDATE_CC(1'15)

  turnoff 
endin

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-10-10 11:28
FromVictor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] [EXTERNAL] [Csnd] problems /bug with ctrlselect
You can open a ticket in github, please give a simple example of the bug there.
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 10 Oct 2024, at 11:21, Philipp Neumann <0000119f78f3a4f9-dmarc-request@LISTSERV.HEANET.IE> wrote:
>
> *Warning*
>
> This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
>
> Hello everybody,
>
> i think i found a bug in the ctrlpreset, ctrlselect and ctrlsave opcodes.
>
> i created a .csd for controlling presets for a midi controller (encoder).
> i can save presets like i want, to a .txt file. in the .txt file everything looks fine. so i guess ctrlsave and ctrlpreset are fine.
> but the problem starts when i recall presets.
>
> to describe the problem, let’s assume i have cc 1 - 4.
> i save a preset-1 with
> cc1: 127
> cc2: 0
> cc3: 0
> cc4: 0
>
> i save preset-2 with
> cc1: 0
> cc2: 127
> cc3: 0
> cc4: 0
>
> now i recall preset-1 and everything is like expected.
> now i change e.g. cc4 manually to 127.
> so the setting is
> cc1: 127
> cc2: 0
> cc3: 0
> cc4: 127
>
> now i want to recall preset-2
> and i get
> cc1: 0
> cc2: 127
> cc3: 0
> cc4: stays 127!!! but should be 0, like i the preset i saved.
>
> here is my .csd. maybe i also did a mistake, but i think i didn’t.
>
> /* opcodes fore midi presets:
> ctrlselect: loads a preset of values via a tag
> ctrlpreset: defines a preset with a tag
> ctrlprintpresets: Prints the current collection of presets for MIDI
>  controllers of a txt file
> */
>
> // macro for updating a midi controller
> ;; gets the current cc of a MIDI controller
> ;; and sends it to itself
> ;; can be used to init a controller with values or update a controller
> ;; after a preset call
> #define UPDATE_CC(Chn'CC)
> #
> i$CC chanctrl $Chn, $CC, 0, 127
> outic $Chn, $CC, i$CC, 0, 127
> #
>
> instr initToZero_faderfoxec4
>  // init all faderfox cc to 0
>  ctrlinit(1,
>    0,0, 1,0, 2,0, 3,0, 4,0, 5,0, 6,0, 7,0, 8,0, 9,0, 10,0, 11,0,
>    12,0, 13,0, 14,0, 15,0)
>
>  $UPDATE_CC(1'0)
>  $UPDATE_CC(1'1)
>  $UPDATE_CC(1'2)
>  $UPDATE_CC(1'3)
>  $UPDATE_CC(1'4)
>  $UPDATE_CC(1'5)
>  $UPDATE_CC(1'6)
>  $UPDATE_CC(1'7)
>  $UPDATE_CC(1'8)
>  $UPDATE_CC(1'9)
>  $UPDATE_CC(1'10)
>  $UPDATE_CC(1'11)
>  $UPDATE_CC(1'12)
>  $UPDATE_CC(1'13)
>  $UPDATE_CC(1'14)
>  $UPDATE_CC(1'15)
>
>  turnoff
> endin
> schedule("initToZero_faderfoxec4", 0, 1)
>
> instr presets_faderfoxec4
>  #include "faderfox-midi-presets.txt"
>  gkMidiData[] ctrlsave 1,\
>    0,1,2,3,4,5,6,7,8,9,10,\
>    11,12,13,14,15
>
>  // selecting preset mode, saving oder calling presets
>  ;; 's' = 115 for save mode
>  ;; 'c' = 99 for call mode
>  iSave = 115
>  iCall = 99
>
>  kChar,kDown sensekey
>  ;;  printks2 "kChar: %d\n", kChar
>  // save trig
>  kSaveTrig init 0
>  if kChar == iSave && kDown == 1 then
>    kSaveTrig = 1
>  else
>    kSaveTrig = 0
>  endif
>
>  // call trig
>  kCallTrig init 0
>  if kChar == iCall && kDown == 1 then
>    kCallTrig = 1
>  else
>    kCallTrig = 0
>  endif
>
>  if kSaveTrig == 1 then
>    event "i", "print_save", 0, 1
>  endif
>  if kCallTrig == 1 then
>    event "i", "print_call", 0, 1
>  endif
>
>  // save or call mode
>  kModeSelect init iCall
>  if kChar != -1 && kDown == 1 then
>    kMode = kChar
>  else
>    kMode = kModeSelect
>  endif
>  kModeSelect = (kMode == iSave) ? iSave : kModeSelect
>  kModeSelect = (kMode == iCall) ? iCall : kModeSelect
>
>  // choosing preset number
>  kPresetNum init 0
>  kPresetNum = (kChar >= 49 && kChar <= 57 ? (kChar - 48) : kPresetNum)
>  kPresetNum = (kChar == 48 ? 0 : kPresetNum)
>  printks2 "Preset Number: %d\n",kPresetNum
>
>  // Save preset
>  kChanged changed kPresetNum
>  printks2 "kChanged: %d\n", kChanged
>  if (kModeSelect == iSave) && (kChanged == 1) then
>    event "i", "savePreset_faderfoxec4", 0, 1, kPresetNum
>  endif
>
>  // call preset
>  if (kModeSelect == iCall) && (kChanged == 1) then
>    event "i", "callPreset_faderfoxec4", 0, 1, kPresetNum
>  endif
> endin
> schedule("presets_faderfoxec4", 0, 6000000)
>
> instr print_save
>  printf "\nPRESET-SAVE-MODE\n",1
>  turnoff
> endin
>
> instr print_call
>  printf "\nPRESET-CALL-MODE\n",1
>  turnoff
> endin
>
> instr savePreset_faderfoxec4
>  printf "\nIS-SAVING PRESET: %d\n",1, p4
>  kPreset ctrlpreset p4, gkMidiData
>  ctrlprintpresets "faderfox-midi-presets.txt"
>  turnoff
> endin
>
> instr callPreset_faderfoxec4
>  printf "\nIS-CALLING PRESET: %d\n",1, p4
>  ctrlselect p4
>  event "i", "updateCC_faderfoxec4", 0, 1
>  turnoff
> endin
>
> instr updateCC_faderfoxec4
>  $UPDATE_CC(1'0)
>  $UPDATE_CC(1'1)
>  $UPDATE_CC(1'2)
>  $UPDATE_CC(1'3)
>  $UPDATE_CC(1'4)
>  $UPDATE_CC(1'5)
>  $UPDATE_CC(1'6)
>  $UPDATE_CC(1'7)
>  $UPDATE_CC(1'8)
>  $UPDATE_CC(1'9)
>  $UPDATE_CC(1'10)
>  $UPDATE_CC(1'11)
>  $UPDATE_CC(1'12)
>  $UPDATE_CC(1'13)
>  $UPDATE_CC(1'14)
>  $UPDATE_CC(1'15)
>
>  turnoff
> endin
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here


Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here