[Prev][Next][Index][Thread]

Re: Here's a midi question for you....



"selena" <smd7@cs.waikato.ac.nz> writes:

> 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



Follow-Ups: References: