How to use the "pitch bend" on midilib.bb library

BlitzPlus Forums/BlitzPlus Beginners Area/How to use the "pitch bend" on midilib.bb library

josé marcos(Posted 2014) [#1]
Hello everyone!
This question was originally written in Portuguese of Brazil, and has been translated with google translator.
I hope it is understandable.

I downloaded a library, developed by Ziltch, to play notes in the midi output windows.
The library is here:
http://www.blitzbasic.com/toolbox/toolbox.php?tool=120

I really enjoyed, and I'm creating my scripts using some features.

I am finding it difficult to use the "pitch bend". If is this possible with this library.

If anyone knows how to do this, I would like an example.

For example, I created the following simple script, to play a single note, using a continuous sounding instrument:

Graphics 800,600,0,2
SetBuffer BackBuffer()
Include "midilib.bb"

MidiChannel = 0
velocity = 100
note =56
instrument =48

MidiOutHandle = OpenMidiOut(0)
SendMidiOut(MidiOutHandle,MidiChannel,MidiProgramChange,instrument)

While Not KeyHit(1)

If KeyDown( 57 ) press = press + 1 Else press = 0

If press = 1 SendMidiOut(MidiOutHandle,MidiChannel,MidiNoteOn,Note,velocity)

If press = 0 SendMidiOut(MidiOutHandle,MidiChannel,MidiNoteOff,Note)

Delay 1
Wend

CloseMidiOut(MidiOutHandle)
End



as you would to include a function that took a bend?

If they can not understand my question, I will try to write otherwise.
Thank you in advance to everyone who can help me.


Kryzon(Posted 2014) [#2]
A pitch bend \ pitch wheel event can be sent using status 14 and it seems to accept a coarse and fine values for the pitch to be set.

So you have...
MidiPitchBend = $E     ;14 in hexadecimal
fine = 0
coarse = 80    ;The range is 0 ~ 127 for either the coarse or fine setting, but remember that it works up and down from the middle, 64.

SendMidiOut( handle, channel, MidiPitchBend, fine, coarse ) ;Send a pitch bend event.

SendMidiOut( handle, channel, MidiPitchBend, 64, 64 ) ;RESET the pitch bend to the centre with 64 fine, 64 coarse.

I used these pages as reference:
- http://www.gmarts.org/index.php?go=321
- http://www.indiana.edu/~emusic/etext/MIDI/chapter3_MIDI4.shtml

I also read the "MidiLib.bb" file from the library to know how the SendMidiOut function works.


josé marcos(Posted 2014) [#3]
Indeed, it was a lot of lack of attention from me. part
I had read the file "midilib.bb" several times, including learning to use the effects, chorus, pan, etc.
He had even looked for the phrase "pitchwheel" and even tried to associate the name, and done some experiments, was not tried as described by you.

Thank you very much even for the help.

The full test code looked like this:

Graphics 800,600,0,2
SetBuffer BackBuffer()
Include "midilib.bb"

MidiChannel = 0
velocity = 100
note =56
instrument =48

MidiOutHandle = OpenMidiOut(0)
SendMidiOut(MidiOutHandle,MidiChannel,MidiProgramChange,instrument)

MidiPitchBend = $E
fine = 0
coarse = 80

While Not KeyHit(1)

If KeyDown( 57 ) press = press + 1 Else press = 0

If press = 1 SendMidiOut(MidiOutHandle,MidiChannel,MidiNoteOn,Note,velocity)

If press = 0 SendMidiOut(MidiOutHandle,MidiChannel,MidiNoteOff,Note)
pitch = 0
If KeyDown( 208 ) And coarse>0 coarse = coarse - 1: pitch=1
If KeyDown( 200 ) And coarse<127 coarse = coarse + 1: pitch = 1
If pitch = 0
If coarse > 64 coarse = coarse - 1
If coarse < 64 coarse = coarse + 1
EndIf
SendMidiOut( MidiOutHandle, MidiChannel, MidiPitchBend, fine, coarse)

Delay 1
Wend

CloseMidiOut(MidiOutHandle)
end


Press the spacebar to play a note, and just use the up and down to raise or lower the note softly.

Again, my sincere thanks for the help.


Kryzon(Posted 2014) [#4]
No problem.
One thing I'm not entirely confident in is the centre\neutral value for the "fine" setting.

On that "gmarts.org" website that I linked to above it states that "fine=0, coarse=64 for centre."
But it doesn't make sense that the center position has "coarse" as 64 and "fine" as zero. "Fine" should be 64 as well.

If you need absolute precision, you should record the sounds played by your program and compare with some other music program to see if there's a difference. That is, if fine=64 and coarse=64 gives a neutral pitch bend, or if fine=0 and coarse=64 is the correct neutral setting.


josé marcos(Posted 2014) [#5]
This is not perceptible by the ear.

In fact, changing the value "fine" has not had any effect.

In a comun midi sequence (at least the windows), I realized that the pitch bend variation is a shade up or down.

The most you can get is the variation of two tones. For example, from what I understand, if I need to change in a "C" of pitch bend to "E", have to use the "D" note with the lower value of PB. "0". And increase to 127.

But I think that you may have noticed!

Only in modern musical keyboards, has a fancier option.
So what I really needed was already solved.

Gracias