Csound Csound-dev Csound-tekno Search About

[Csnd] quartertone piano

Date2011-08-24 12:46
FromTarmo Johannes
Subject[Csnd] quartertone piano
Attachmentsquartertone-piano.csd  
Hello,

Some time ago Miquel Parera suggested a great piano soundfont on http://zenvoid.org/audio.html
My wife, who is a composer, often needs to check some quarter-tone melodies or harmonies, I  built some instruments to play quarter-tones on a normal midi keyboard.

The first suggestion of my wife was to get a quarter-tone when a key is hit twice (instr 3 in the attached csd). The problem is that when a key is pressed, the instrument does not know if there is another hit coming. So there must be some delay before the actual sound is played. So the latency of the instrument is a bit too big and it is also a bit clumsy to play.

The other idea was to get a quartertone, if two nabouring keys are pressed simultaneously  (instr 2). That is much more comfortable, only one cannot play a qartertone interval together (like c and c-1/4 sharp) because the c key is are already in use (but this it is possible with the succession instrument (inst 3).

It was relatively simple to do with synthesized sound as you can easily calculate the frequency, put in delays etc. So instr 2 and 3 use a GBUZZ based synthesized sound (instr 100 ). The GBUZZ code was borrowed from a mail by  
Dennis Raddle  on 05.08.11. Thanks!

But the target was to have the same effect with piano sound and use fluidsynth opcodes. It was much more complicated as the midi world is so much more rigid...  To achieve the quarter-tones I use  pitchbend (MIDI command 224, first data byte 0, second 0..127, middle is 64, so normatl+1/4 tone is 80) on the second channel and send the needed quartertone notes there. The biggest problem was to control which keystrokes have to make sound and which not - when two neighbouring keys are pressed, one is slightly after, but the first one does not know it and actually none of the two pitches has to played but the quarter-tone in between them instead.  fluidNote runs at i-time so you really cannot use any delay or envelope or k-konditions anything on it.

I ended up in a bunch of different instrument and condition lines but I got it work! (instr 1). There are more comments in the code.
Maybe there are much more straightforward ways to do it, please let me know!

Or if you find the QT-piano it useful, please go ahead ana use it!

greetings,
tarmo
--------


; Quarter-tone piano on a midi keyboard. Use channel 1 to play instr 1, channel 2 for instr 2 etc
; Tarmo Johannes tarmo@otsakool.edu.ee


-odac  +rtmidi=alsa -Ma -d



sr = 44100
nchnls = 2
0dbfs = 1
ksmps = 32

;massign 0,1 ; if you like

#define VERY_CLOSE #0.2#
#define SAME_TIME #0.03#

; tables
giCosine	ftgen	0, 0, 2048, 11, 1
giMidiNotes ftgen 0,0,128, -2, 0 ; store times when the keys are  pressed here

; --- Fluidsynth engine and soundfont
giengine fluidEngine
isfnum	 fluidLoad "/home/tarmo/muusika/SFBank/acoustic_grand_piano_ydp_20080910.sf2", giengine, 1
fluidProgramSelect giengine, 1, isfnum, 0, 0
fluidProgramSelect giengine, 2, isfnum, 0, 0 ; load the fot also to channel 2. QT-s are played in channel 2 with pitchbend

	 
	 
instr 3 ; QT when a key is hit twice within $VERY_CLOSE seconds
	inotenum notnum
	icps cpsmidi
	itime times
	
	ioldtime tab_i inotenum, giMidiNotes ; read when the same note was pressed before
	;print ioldtime
	
	if itime-ioldtime <= $VERY_CLOSE then ; if it is a repeating stroke, calculate the new frequency		
		icps= icps*cent(50)
		prints "very close!\n" 
	endif
	
	iamp ampmidi 0.3
	print itime,icps
	idelay=$VERY_CLOSE/2 
	kamp madsr 0.05,0.1,0.3,0.2,idelay ; introduce some delay that the first of the repeated notes would not be heard. So all the notes are played later.
	
	
	; code from Dennis Raddle
	i_num_harm = sr/icps/2
	i_low_harm = 1
	i_mult = 0.5
	
	asig gbuzz iamp*kamp, icps, i_num_harm, i_low_harm, i_mult, giCosine
	
	;asig oscil iamp*kamp,icps,giSine
	
	outs asig,asig
	
	tabw_i itime, inotenum, giMidiNotes ; write the time of the current stroke to the table at the position of the MIDI note number
endin


instr 2 ; plays quartertone when naighbouring keys are pressed simultaneously
	inotenum notnum
	icps cpsmidi
	iamp ampmidi 0.5
	itime times
	tabw_i itime, inotenum, giMidiNotes ; write the time to the position of the MIDI note number
	
	; read when the neigbouring notes ere pressed
	itime_upper tab_i inotenum+1, giMidiNotes 
	itime_lower tab_i inotenum-1, giMidiNotes 
		
	if (itime-itime_upper <= $SAME_TIME) then
		prints "TOGETHER WITH UPPER NOTE\n";
		icps= icps*cent(50)
		turnoff2 100+((inotenum+1)/1000), 12, 1 ; turn off the upper note, instr 100 is the one making sound. The fraction part of the instno carries key number, so it can be identified
	endif
	
	if (itime-itime_lower <= $SAME_TIME) then 
		prints "TOGETHER WITH LOWER NOTE\n";
		icps= icps*cent(-50)
		turnoff2 100+((inotenum-1)/1000), 12, 1 ; turn off the lower note
	endif
	
	insnum= 100+inotenum/1000
	event_i "i", insnum,0,-1,iamp,icps,$SAME_TIME
	
	kend      release   ;get a "1" if instrument is turned off
	if kend == 1 then
	 	     turnoff2 insnum, 12, 1 ; kmode=12 - turn of with exact fractional number, MIDI notes or similar 
	endif
	
endin

instr 1 ; plays quartertone on fluidsynth with laoded soundfont when neigbouring keys are pressed simultanously
	inotenum notnum
	ivel veloc
	itime times
	tabw_i itime, inotenum, giMidiNotes ; write the time of the stroke to the position of the MIDI note number

	timout 0,$SAME_TIME,nothing ; wait, to see if neigbouring note will be perssed
	
	kDone init 0
	if kDone!=1 then; do it only once
		
		ktime times ; what is the time now after timout?
    	ktime_upper tab inotenum+1, giMidiNotes ; read when the neighouring notes were pressed
		ktime_lower tab inotenum-1, giMidiNotes ;
		
		; the conditions below assume that one of the keys is pressed sligthly before. If the values are absolutely equal, put there a small difference, to make the code work
		if ktime_lower=itime then
			ktime_lower=itime+0.001
		endif
		if ktime_upper=itime then
			ktime_upper=itime+0.001
		endif
		
		; check if the quartertone is already played
		
		if ( (itime-ktime_upper <= $SAME_TIME) && (itime-ktime_upper > 0) ) || ((itime-ktime_lower <= $SAME_TIME) && (itime-ktime_lower > 0) ) then ; if this is SECOND note of the pair, the work is already done, leave. 
			
			kDone=1
			kgoto nothing
		endif 
		
		if (ktime-ktime_upper <= $SAME_TIME) then
			printks "TOGETHER WITH UPPER NOTE\n",0;
			kNotenum=inotenum
			kQuarter=1 ; play in second channel
						
		elseif (ktime-ktime_lower <= $SAME_TIME) then ; when the lower chromatic nabour was pressed first			
			printks "TOGETHER WITH LOWER NOTE\n",0;
			kNotenum=inotenum-1 ; play as the lower one + 1/4 tone
			kQuarter=1
		else
			printks "NORMAL NOTE\n",0;
			kNotenum=inotenum
			kQuarter=0
		endif
		
		event "i",4+kNotenum/1000,0,-1,kNotenum, ivel, kQuarter
		kDone=1
	endif
	
	kend      release   ;get a "1" if instrument is turned off
 	if kend == 1 then
        event "i",-(4+kNotenum/1000),0,0
 	endif

nothing:
   	
endin


instr 4 ; play the actual fluidNote
	
	ikey=p4
	ivel=p5
	iquart=p6 ; 1 if it has to be  ikey+quartertone
	
	ichannel= (iquart == 0 ? 1 : 2 ) ; 2nd channel for quartertones
	fluidNote giengine, ichannel, ikey, ivel
endin




instr 100 ; make sound (GBUZZ)
	iamp=p4
	ifreq=p5
	idelay=p6
	
	kamp linsegr 0, idelay, 0, .05, 1, .1, .4, 4, .03, .2, 0 ;madsr 0.05,0.1,0.3,0.2,idelay
	
	i_num_harm = sr/ifreq/2
	i_low_harm = 1
	i_mult = 0.5
	
	asig gbuzz iamp*kamp, ifreq, i_num_harm, i_low_harm, i_mult, giCosine
		
	outs asig,asig
endin

instr 200 ; output the sound from fluidengine
	
	fluidControl giengine, 224, 2, 0, 80 ; send pitchbend +quartertone constantly to the 2nd channel
	
	imvol  init 15 ; coreect the amplitude
	asigl, asigr fluidOut giengine
    ;asigl delay asig, idlt [, iskip]
    outs asigl*imvol, asigr*imvol

endin



f 0 600

i 200 0 600 ; fluidsynth to audio instr





Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Date2011-08-28 07:03
FromJim Aikin
Subject[Csnd] Re: quartertone piano
I've done a lot of microtonal playing on a conventional MIDI keyboard, using
Csound and other synthesizers. The easy thing to do is probably to convert
the MIDI note number into a pitch-class value and then use cpsxpch to
produce 24 pitches per octave. This will, of course, change the keyboard
technique rather drastically, but if you're planning to play quarter-tones
you'll have to change your technique _somehow_.

If that doesn't appeal, a second alternative is to use a MIDI footswitch
(transmitting something other than the sustain pedal command, CC 64) to jump
the keyboard up by a quarter-tone when the pedal is down. With this setup
you couldn't play simultaneous intervals outside of a 12ET octave ... and
indeed, you'd have a bit of a coding problem to solve in sustaining keys
across a pedal-press or pedal-release. But it could be done.

Think about a harp, though. The harpist has seven pedals, one for each
diatonic note, and each pedal has three possible positions. With an
organ-type MIDI pedalboard (not a common accessory, but I'm sure you can
find one somewhere) you could separately raise each of the 12 keys on the
keyboard by a quarter-tone by tapping the corresponding footpedal. This
would give you much more freedom to play simultaneous intervals involving
quarter-tones without altering your keyboard technique in any significant
way.

Having said all that, I'd like to add, as an aside ... quarter-tones? The
24ET scale is not very interesting harmonically, in my opinion. 19ET and
31ET are fascinating both harmonically and melodically. 17ET is more
exotic-sounding, but quite usable.

Just my 2 cents' worth. Everybody has their own taste in tunings. Lots of
people are enamored of Bohlen-Pierce, and I can't deal with it at all.

--Jim Aikin

--
View this message in context: http://csound.1045644.n5.nabble.com/quartertone-piano-tp4730137p4742756.html
Sent from the Csound - General mailing list archive at Nabble.com.


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-08-28 14:21
FromTarmo Johannes
SubjectRe: [Csnd] Re: quartertone piano
Thank you for continuing the discussion,

On Sunday 28 August 2011 09:03:29 Jim Aikin wrote:
> I've done a lot of microtonal playing on a conventional MIDI keyboard, using
> Csound and other synthesizers. The easy thing to do is probably to convert
> the MIDI note number into a pitch-class value and then use cpsxpch to
> produce 24 pitches per octave. 

icps cpsxpch ipch, iequal, irepeat, ibase

is a good hint. As I understand, it enables to build also non-tempered scales if the "iequal" is negative and in the table pointed by it hold the multipliers of the steps of the division.

But that (like also using extra fraction numbers like cpspch(8.0125) or  cent(x) ) assumes that you are using synthesized sound where you can affect the frequency and not midi-produced sound as fluidsynth or external midi player. 
I tried to use an existing sound font with fluidsynth opcodes.

> 
> Think about a harp, though. The harpist has seven pedals, one for each
> diatonic note, and each pedal has three possible positions. With an
> organ-type MIDI pedalboard (not a common accessory, but I'm sure you can
> find one somewhere) you could separately raise each of the 12 keys on the
> keyboard by a quarter-tone by tapping the corresponding footpedal. This
> would give you much more freedom to play simultaneous intervals involving
> quarter-tones without altering your keyboard technique in any significant
> way.
This is an interesting idea. Another possibility is to use two keyboards - one is pitch-shifte 1/4 tone up (or however one likes).
For example an early microtone composer and pianist Ivan Vyshnegradsky let himself build a quartertone piano at first with split keys (in 1940ies!), but later used two pianos tuned 1/4 tone apart. Also Georg Friedrich Haas has some pieces for one pianist on two pianos a quartertone apart. This works better for harmonic music, for melodic lines  I find my quartertone with two cromatic nabours quite good.



> 
> Having said all that, I'd like to add, as an aside ... quarter-tones? The
> 24ET scale is not very interesting harmonically, in my opinion. 
I agree. Also melodically the pefect 50-cent intervals seem to me without expression and relation to other steps. But for example for my wife it is exactly what she imagines and wants to get.

greetings,
tarmo

> 19ET and
> 31ET are fascinating both harmonically and melodically. 17ET is more
> exotic-sounding, but quite usable.
interesting, I should try it out.

tarmo

> 
> Just my 2 cents' worth. Everybody has their own taste in tunings. Lots of
> people are enamored of Bohlen-Pierce, and I can't deal with it at all.
> 
> --Jim Aikin
> 
> --
> View this message in context: http://csound.1045644.n5.nabble.com/quartertone-piano-tp4730137p4742756.html
> Sent from the Csound - General mailing list archive at Nabble.com.
> 
> 
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
> 
> 


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-08-28 20:30
FromBrian Redfern
SubjectRe: [Csnd] Re: quartertone piano

Another way to tackle it is to either put a tuning box in between the keyboard and csound or get an arabic arranger keyboard like the casio at3 where the controller itself does quarter tuning. The sounds on that keyboard are somewhat amateurish so its fairly cheap, but driving a bunch of csound instruments via midi you can switch up quarter tone scales in realtime from the controller without writing a bunch of gruesome code on the csound side.

On Aug 28, 2011 6:24 AM, "Tarmo Johannes" <tarmo@otsakool.edu.ee> wrote:
> Thank you for continuing the discussion,
>
> On Sunday 28 August 2011 09:03:29 Jim Aikin wrote:
>> I've done a lot of microtonal playing on a conventional MIDI keyboard, using
>> Csound and other synthesizers. The easy thing to do is probably to convert
>> the MIDI note number into a pitch-class value and then use cpsxpch to
>> produce 24 pitches per octave.
>
> icps cpsxpch ipch, iequal, irepeat, ibase
>
> is a good hint. As I understand, it enables to build also non-tempered scales if the "iequal" is negative and in the table pointed by it hold the multipliers of the steps of the division.
>
> But that (like also using extra fraction numbers like cpspch(8.0125) or cent(x) ) assumes that you are using synthesized sound where you can affect the frequency and not midi-produced sound as fluidsynth or external midi player.
> I tried to use an existing sound font with fluidsynth opcodes.
>
>>
>> Think about a harp, though. The harpist has seven pedals, one for each
>> diatonic note, and each pedal has three possible positions. With an
>> organ-type MIDI pedalboard (not a common accessory, but I'm sure you can
>> find one somewhere) you could separately raise each of the 12 keys on the
>> keyboard by a quarter-tone by tapping the corresponding footpedal. This
>> would give you much more freedom to play simultaneous intervals involving
>> quarter-tones without altering your keyboard technique in any significant
>> way.
> This is an interesting idea. Another possibility is to use two keyboards - one is pitch-shifte 1/4 tone up (or however one likes).
> For example an early microtone composer and pianist Ivan Vyshnegradsky let himself build a quartertone piano at first with split keys (in 1940ies!), but later used two pianos tuned 1/4 tone apart. Also Georg Friedrich Haas has some pieces for one pianist on two pianos a quartertone apart. This works better for harmonic music, for melodic lines I find my quartertone with two cromatic nabours quite good.
>
>
>
>>
>> Having said all that, I'd like to add, as an aside ... quarter-tones? The
>> 24ET scale is not very interesting harmonically, in my opinion.
> I agree. Also melodically the pefect 50-cent intervals seem to me without expression and relation to other steps. But for example for my wife it is exactly what she imagines and wants to get.
>
> greetings,
> tarmo
>
>> 19ET and
>> 31ET are fascinating both harmonically and melodically. 17ET is more
>> exotic-sounding, but quite usable.
> interesting, I should try it out.
>
> tarmo
>
>>
>> Just my 2 cents' worth. Everybody has their own taste in tunings. Lots of
>> people are enamored of Bohlen-Pierce, and I can't deal with it at all.
>>
>> --Jim Aikin
>>
>> --
>> View this message in context: http://csound.1045644.n5.nabble.com/quartertone-piano-tp4730137p4742756.html
>> Sent from the Csound - General mailing list archive at Nabble.com.
>>
>>
>> Send bugs reports to the Sourceforge bug tracker
>> https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>
>>
>
>
> Send bugs reports to the Sourceforge bug tracker
> https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>