Here's a midi question for you.... 
Author Message
 Here's a midi question for you....

I have a created a midi event with all the details and want to place a
pointer to this event in the lpData-value field of the MIDIHDR structure.
The lpData-value field needs to be of type <LPSTR>, and in the C code this
field is accessed by using

midiHdr.lpData = (LPBYTE)&phrase[0];   // (when accessing an array as
opposed to a midi event)

How do I do this in Dylan????

// declarations of the two midi structures
let LPmidievent = make (<LPMIDIEVENT>); // This could be an array/vector of
midi instructions instead
let LPmidihdr = make(<LPMIDIHDR>);

// Any ideas
LPmidihdr.lpData-value :=  ???;  // This needs to point to the midievent

Thanks in advance
Selena
(Dylan Defn's below)

NOTE:

define C-struct <MIDIHDR>
  sealed inline-only slot lpData-value   :: <LPSTR>;
  sealed inline-only slot dwBufferLength-value :: <DWORD>;
  sealed inline-only slot dwBytesRecorded-value :: <DWORD>;
  sealed inline-only slot dwUser-value   :: <DWORD>;
  sealed inline-only slot dwFlags-value  :: <DWORD>;
  sealed inline-only slot lpNext-value   :: <LPMIDIHDR>;
  sealed inline-only slot reserved-value :: <DWORD>;
  sealed inline-only slot dwOffset-value :: <DWORD>;
  sealed inline-only array slot dwReserved-array :: <DWORD>,
 length: 8, address-getter: dwReserved-value;
  pack: 1;
  pointer-type-name: <LPMIDIHDR>;
  c-name: "struct midihdr_tag";
end C-struct <MIDIHDR>;

define C-struct <MIDIEVENT>
  sealed inline-only slot dwDeltaTime-value :: <DWORD>;
  sealed inline-only slot dwStreamID-value :: <DWORD>;
  sealed inline-only slot dwEvent-value  :: <DWORD>;
  sealed inline-only array slot dwParms-array :: <DWORD>, length: 1,
 address-getter: dwParms-value;
  pack: 1;
  pointer-type-name: <LPMIDIEVENT>;
  c-name: "struct midievent_tag";
end C-struct <MIDIEVENT>;



Sun, 03 Nov 2002 03:00:00 GMT  
 Here's a midi question for you....

Quote:

> midiHdr.lpData = (LPBYTE)&phrase[0]; // (when accessing an array as
> opposed to a midi event)

> How do I do this in Dylan????

pointer-cast is what you are looking for I think. Try something like:

  let event = make(<LPMIDIEVENT>);
  let header = make(<LPMIDIHDR>);
  header.lpData-value := pointer-cast(<LPSTR>, event);

To get the size of the structure for the next element:

  header.dwBufferLength-value := size-of(<MIDIEVENT>);

Don't use size-of(<LPMIDIEVENT>) as this returns the size of the
pointer which is 4. Don't forget to use 'destroy' on your pointers
when you are finished with them:

  destroy(header);
  destroy(event);

You can use with-stack-structure to do this for you:

  with-stack-structure(event :: <LPMIDIEVENT>)
    with-stack-structure(header :: <LPMIDIHDR>)
      header.lpData-value := pointer-cast(<LPSTR>, event);
      header.dwBufferLength-value := size-of(<MIDIEVENT>);
      do-something(header);
    end;
  end;

With an array, use something like:

  with-stack-structure(events :: <LPMIDIEVENT>, element-count: 20)
    with-stack-structure(header :: <LPMIDIHDR>)
      header.lpData-value := pointer-cast(<LPSTR>, events);
      header.dwBufferLength-value := size-of(<MIDIEVENT>) * 20;  
      do-something(header);
    end;
  end;

Chris.
--
http://www.double.co.nz/dylan



Sun, 03 Nov 2002 03:00:00 GMT  
 Here's a midi question for you....
Thanks Chris,
but still having troubles..... :o(

// My Code

// creating the midi event (only one)
let LPmidievent = make (<LPMIDIEVENT>);
LPmidievent.dwEvent-value := (#x007F3C90);

// creating the midi header
let LPmidiheader = make(<LPMIDIHDR>);
// LPmidiheader.lpData-value := c-type-cast(<LPSTR>, LPmidievent);
LPmidiheader.lpData-value := pointer-cast(<LPSTR>, LPmidievent);
LPmidiheader.dwBufferLength-value := size-of(<MIDIEVENT>);
LPMidiheader.dwBytesRecorded-value := size-of(<MIDIEVENT>);

Thanks for the pointer-cast tip, I'd been using c-type-cast(<LPSTR>, event);
(although I think this has the same effect) and thought it was this causing
the problem but
with pointer-cast, I'm still getting the same error so perhaps it's
something else.....

I get an error when calling midiStreamOut after this :

 result := midiOutPrepareHeader(outHandle, LPmidiheader,
size-of(<MIDIHDR>));
 result := midiStreamOut(outHandle, LPmidiheader, size-of(<MIDIHDR>));

result stores the error value 11 giving the message (in midiOutGetErrorText)
'An invalid parameter was passed to a system function'

It may just be a matter of altering each of the values until I find the
problem......

Selena



Mon, 04 Nov 2002 03:00:00 GMT  
 Here's a midi question for you....

Quote:

> Thanks for the pointer-cast tip, I'd been using c-type-cast(<LPSTR>,
> event); (although I think this has the same effect) and thought it
> was this causing the problem but with pointer-cast, I'm still
> getting the same error so perhaps it's something else.....

c-type-cast is similar to pointer-cast except it can be used in more
situations. pointer-cast will only convert from one pointer type to
another. c-type-cast can convert other c types as well (for example, a
long to a pointer, etc).

Quote:
> I get an error when calling midiStreamOut after this :

>  result := midiOutPrepareHeader(outHandle, LPmidiheader,
> size-of(<MIDIHDR>));
>  result := midiStreamOut(outHandle, LPmidiheader, size-of(<MIDIHDR>));

> result stores the error value 11 giving the message (in
> midiOutGetErrorText) 'An invalid parameter was passed to a system
> function'

I've had similar problems when using API calls with structures without
clearing out the structure to zero first. Try using clear-memory!
after creating the structures:

  let event = make(<LPMIDIEVENT>);
  clear-memory!(event, size-of(<MIDIEVENT>));
  let header = make(<LPMIDIHDR>);
  clear-memory!(header, size-of(<MIDIHDR>));

I think this is likely to be the problem if you haven't already
explicity set each element of the structure to a valid value (like
0).

Chris.
--
http://www.double.co.nz/dylan



Mon, 04 Nov 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. MIDI file parser, MIDI classes

2. Midi into RB app's HOW?

3. Midi Made Easy - Here's how

4. MIDI and 8051 uC's

5. Serial Port, Midi and Window Placement Questions

6. Midi in Cosmo (no) in Windows (yes) Question AND ANSWER

7. lisp to midi question

8. question: 'A'..'k'

9. Beginner's 'enum' question

10. ABC 'Recursive' File Question

11. A Question about 'creation' Clauses

12. CMS 'GLOBALV' question

 

 
Powered by phpBB® Forum Software