Re: [Csnd-dev] Art's Issue

Michael Gogins <[email protected]>
Newsgroups gmane.comp.audio.csound.devel
Message-ID <CAFswGP1YvMX_LsByZWLLRMXdTpKAYAW3Mc0PMfUfEw=0p7=SSA@mail.gmail.com>
On my macOS I tested your .csd and also created my own .csd (attached)
which behaved as follows:

Both files received keystrokes and translated them to MIDI messages that
were sent out from Csound.

Both files recorded valid MIDI files that I could load into Reaper and play.

Only the first keystroke actually played a note on the synth. All the other
keystrokes, though they continued to be translated and to be saved, were
silent.

When the user ended the Csound performance with Control-C, the Midiview app
on the Mac showed all the note off messages arriving at once; no trace of
the note on messages.

This issue describes similar behavior experienced by another user:
https://github.com/csound/csound/issues/1784

Regards,
Mike

-----------------------------------------------------
Michael Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com


On Thu, Aug 14, 2025 at 7:01 PM Arthur Hunkins <[email protected]> wrote:

> Hi, Mike -
>
> Good and helpful discussion this afternoon.
>
> Glad to have any feedback regarding my issue as demoed in the attached
> .csd.
>
> The problem is simple: run as is, everything works as expected, *except* that
> the MIDI file written is empty. This is associated with the fact that the
> duration of performance (via ASC keyboard, the first 8 number keys) is
> infinite (z) and must be stopped by CTRL-C.
>
> Changing the z infinite duration to a finite number (say 5 or 10) finishes
> the performance normally and writes an appropriate MIDI file. (Try it and
> see/verify.)
>
> According to Victor L., z (CTRL-C) should write a proper MIDI file as
> well. This is the only issue. The audio performance depends on the right -Q
> value, but the MIDI file output seems totally independent of this.
>
> Actually, as long as you have some kind of MIDI device plugged in (or an
> active MIDI cable), you can test this out without any audio at all. Just
> see whether the MIDI file (which if Csound runs, will be created) has any
> bytes!
>
> Thanks for any insight. Victor suggests that "this is a Windows problem" -
> which may well be true. (Do you find the same results with Mac or Linux?)
>
> Art H.
>
senskey_test.txt (text/plain, 1.6 KB)
<CsoundSynthesizer>
<CsLicense>
Run this .csd after starting your MIDI controlled instrument. I have tested 
this with the standalone Pianoteq.

There is a problem in that all keystroke events are correctly scheduled and 
the MIDI file is correctly recorded for all keystrokes -- but only the first 
keystroke actually makes a sound.

When the Csound performance is ended with Ctrl-C, then the Midiview app 
finally shows events from all keystrokes being turned off. But the initial 
NOTE ON events are never shown (except for the very first).
</CsLicense>
<CsOptions>
-m167 -odac -d -Q2 -+rtmidi=PortMidi --midioutfile="senskey_test.mid"
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 128
nchnls = 2
0dbfs = 1
gk_channel init 1

instr 1
; The `sensekey` opcode does not return 1 for `k_pressed` as long as the kay 
; is actually held down, then return 0 when the key is released; rather, the 
; opcode 'emulates' this behavior by returning 0 immediately after returning 
; 1. Therefore, `sensekey` cannot provide a duration for key presses without 
; some more elaborate code that 'latches' the keyboard state. Here, we simply 
; send a short fixed duration that represents a struck bell.
k_onset init 0
k_duration init .01
k_velocity init 80
k_key sensekey 
if k_key > 0 then
schedulek 2, k_onset, k_duration, k_key
endif
endin

instr 2
i_channel = 1
i_key = p4
i_velocity init 80
i_duration init .01
noteondur i_channel, i_key, i_velocity, i_duration
prints "MIDI note: channel %9.4f key %9.4f velocity %9.4f duration %9.4f\n", i_channel, i_key, i_velocity, i_duration
endin

</CsInstruments>
<CsScore>
f 0 2000
i 1 0 2000
</CsScore>
</CsoundSynthesizer>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.