steverod (15) [Avatar] Offline
#1
How can I change this example so that echo back only echos back one unique pitch, like middle, but still echos back the other midi data? I know alittle about c++. Thanks
KUMA (56) [Avatar] Offline
#2
Re: Chapter 10 ex3 - How do I make a small change?
The point is ProcessMidiData()(cf.p145); modify it adequately, and you will be able to implement that.
steverod (15) [Avatar] Offline
#3
Re: Chapter 10 ex3 - How do I make a small change?
Thanks for that . I'll let you know how I get on.
steverod (15) [Avatar] Offline
#4
Re: Chapter 10 ex3 - How do I make a small change?
Sorry to be this basic. I would think I would need an if statement to change all key on and key off 's to key 60 (0xC3). in ProcessMidiData. You couldn't suggest one?

Thanks so much.
KUMA (56) [Avatar] Offline
#5
Re: Chapter 10 ex3 - How do I make a small change?
Do you want to convert all notes to middle c when echoed? I thought you wanted to filter notes.
steverod (15) [Avatar] Offline
#6
Re: Chapter 10 ex3 - How do I make a small change?
Yes, that's right. Change all Key on and key off notes to middle C but keep velocity data unchanged. It's to do with teaching the piano.
KUMA (56) [Avatar] Offline
#7
Re: Chapter 10 ex3 - How do I make a small change?
OK, I think the easiest way to convert, for example, every note of channel 1 to middle c is to insert the followig sentence to that function:

if(lpEvent->status == 0x90 || lpEvent->status == 0x80)
lpEvent->data1 = 0xC3;
steverod (15) [Avatar] Offline
#8
Re: Chapter 10 ex3 - How do I make a small change?
I've pu the code in - it's very close, but I get no sound echo'd back and the traceon reads 90 C3 90 C3 90 C3 all the time so no velocity data. Can you help? Once again many thanks.


// ProcessMidiData
//---------------------------------------------------------------------------
BOOL MyMidiIn:smilierocessMidiData(LPMIDIEVENT lpEvent)
{
// display the data, either as hex or trace
if(lpEvent->status == 0x90 || lpEvent->status == 0x80)
lpEvent->data1 = 0xC3;

if(DisplayMode == RAWMODE)
DisplayRawMidi(GetOwner(), lpEvent);
else
DisplayTrace(GetOwner(), lpEvent);

if(EchoOut && ThruEnabled)
EchoOut->Put(lpEvent);

return TRUE;
}
KUMA (56) [Avatar] Offline
#9
Re: Chapter 10 ex3 - How do I make a small change?
ThruEnabled is not defined in the example of Ch10; have you defined it?
The pointer lpEvent points at an structure proper to MaxMidi(cf.p.45); I suspect DisplayRawMidi() and DisplayTrace() are inappropreate to display it.
KUMA (56) [Avatar] Offline
#10
Re: Chapter 10 ex3 - How do I make a small change?
Sorry, I was wrongheaded. You have modified MidiSpy. For now I don't know why it doesn't work well.

After Thought(May 9, 2005)

I have found what was wrong. The note number.


Message was edited by: KUMA
KUMA (56) [Avatar] Offline
#11
Re: Chapter 10 ex3 - How do I make a small change?
Maybe you will need to have echoback enabled. Then change display mode to trace, and you will find it works fine.
steverod (15) [Avatar] Offline
#12
Re: Chapter 10 ex3 - How do I make a small change?
Sorry I should have said midispy. I've tried various menu options. Could it be doing the same operation on each component of an array which also contains Data2. Sorry is that nonsense?
KUMA (56) [Avatar] Offline
#13
Re: Chapter 10 ex3 - How do I make a small change?
What is the value of note on velocity in trace mode display?
Does the original version of MidiSpy work correctly?

Anyway how about working with the example of Ch10?
steverod (15) [Avatar] Offline
#14
Re: Chapter 10 ex3 - How do I make a small change?
I've tried putting your lines in several places in that process with differing results. The trace either works fine (as Midispy) or just 90 C3 90 C3 ..... The velocity data is getting lost. I used Midispy because I had to choose which device and enable thru. Unmodified Midispy works fine.
KUMA (56) [Avatar] Offline
#15
Re: Chapter 10 ex3 - How do I make a small change?
As you say, the sentence can be put into several points; does echoback not work in all cases?
That hex mode display shows '90 C3 90 C3 ...' seems to mean the display routine doesn't work correctly. If all the velocities are changed to 0, it will show in hex mode '90 C3 00 90 C3 00' and in trace mode something like this for one note:
Note On: Note = 60 Velocity = 0 time = x
Note On: Note = 60 Velocity = 0 time = y
(Your keyboard seems to utilize note on with velocity 0 instead of note off.)

Anyway I recommend you to check that if the modified and unmodified version of the example of Ch10 work well. (The example will have device menus, though echoback will be always enabled.)
steverod (15) [Avatar] Offline
#16
Re: Chapter 10 ex3 - How do I make a small change?
I've tried Ch10. The unmodified works fine and does echo back. The modified has the same problem as Midispy has. The traceon in Midispy seems to suggest the velocity data is being ignored.
KUMA (56) [Avatar] Offline
#17
Re: Chapter 10 ex3 - How do I make a small change?
Sorry, I don't know what's going on. It's beyond my ability.
steverod (15) [Avatar] Offline
#18
Re: Chapter 10 ex3 - How do I make a small change?
Thanks a lot for trying.
KUMA (56) [Avatar] Offline
#19
Re: Chapter 10 ex3 - How do I make a small change?
Sorry, I lost the point written on p.67. It seems that the pointer lpEvent can't be used to change data.
Probably the following modification will go.
Put the following lines above the constructor of MyMidiIn.cpp of MidiSpy:

MidiEvent EvtOn;
EvtOn.status = 0x90;
EvtOn.data1 = 0x3C;

MidiEvent EvtOff;
EvtOff.status = 0x80;
EvtOff.data1 = 0x3C;
EvtOff.data2 = 0x00;

and replace ProcessMidiData with this:

BOOL MyMidiIn:smilierocessMidiData(LPMIDIEVENT lpEvent)
{
// display the data, either as hex or trace
if(DisplayMode == RAWMODE)
DisplayRawMidi(GetOwner(), lpEvent);
else
DisplayTrace(GetOwner(), lpEvent);

if(EchoOut && ThruEnabled)
{
if(lpEvent->status == 0x90)
{
EvtOn.data2 = lpEvent->data2;
EchoOut->Put(&EvtOn);
}
else if(lpEvent->status == 0x80) EchoOut->Put(&EvtOff);
else EchoOut->Put(lpEvent);
}
return TRUE;
}
steverod (15) [Avatar] Offline
#20
Re: Chapter 10 ex3 - How do I make a small change?
Thanks so much for having another look. I've put the first lines above the constructor but get 20 errors like these:
C:Maximum MIDIExample AppsMidiSpyMyMidiIn.cpp(3smilie : error C2143: syntax error : missing ';' before '.'
C:Maximum MIDIExample AppsMidiSpyMyMidiIn.cpp(3smilie : error C2501: 'EvtOn' : missing storage-class or type specifiers
C:Maximum MIDIExample AppsMidiSpyMyMidiIn.cpp(3smilie : error C2371: 'EvtOn' : redefinition; different basic types
C:Maximum MIDIExample AppsMidiSpyMyMidiIn.cpp(35) : see declaration of 'EvtOn

It accepts the identifier lines but not the others.
KUMA (56) [Avatar] Offline
#21
Re: Chapter 10 ex3 - How do I make a small change?
How about putting the declarations into MyMidiIn.h like this:

class MyMidiIn : public CMaxMidiIn
{
MidiEvent EvtOn;
MidiEvent EvtOff;
......
}

and the rest into the constructor like this:

MyMidiIn::MyMidiIn()
{
EvtOn.status = 0x90;
EvtOn.data1 = 0x3C;
EvtOff.status = 0x80;
EvtOff.data1 = 0x3C;
EvtOff.data2 = 0x00;
......
}

By the way, I can't find any reason why lpEvent can't be used to change data.
steverod (15) [Avatar] Offline
#22
Re: Chapter 10 ex3 - How do I make a small change?
Fantastic. That worked! Thanks a lot. If there's anything I can do for you (I'm a London based piano teacher) let me know. My email is at keyboardclass.com.
KUMA (56) [Avatar] Offline
#23
Re: Chapter 10 ex3 - How do I make a small change?
Sorry to have misled you at some points. I'm not a programmer but a musician. In order to modify SMF for a specific use I got the book. After solving the problem, I have been only reading the codes to see how it works. Trying to answer other's question is a good way of learning for me; in this case, too. Thank you.