Guidance
指路人
g.yi.org
software / rapidq / Examples / Audio & Video / midi / MIDI Position.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'>
'> I have an object lyrics that contain several properties and one in
'particuliar
'> that holds the abs position of the word within the current song.
'>
'> Is there a way to do something like this ??
'>
'> on timer event
'> retrieve the current position of the file
'> - mciSendString ("?", ?, ?, ?)
'> if filePosition = WordPosition then
'> change color of word
'> end if
'> end timer event
'>
'> Again thanks for your response!
'> If you say i can i think i'm gonna really love mci stuff !! -:) and
'RQ++
'>

'From: Alain "midiprog2000" <midiprog2000@y...> Mon Oct 28, 2002  4:56 pm

'Yep, it is possible.

'To retreive the position you could use this function, (you need to
'paste the code into your program, code not working without proper MCI-
'declarations etc...)

'----------- start code -----------
     DECLARE FUNCTION Elapsed AS STRING
     DIM L AS STRING
     L = SPACE$(30)
     DIM Mins AS INTEGER
     DIM Sec AS INTEGER
     DIM QueryStr AS STRING
     QueryStr = SPACE$(30)

     FUNCTION Elapsed()
      mciSendString("set music time format ms", "", 0, 0)
      mciSendString("Status music position",VARPTR(QueryStr),30,0)

      sec = ROUND(VAL(MID$(QueryStr, 1, LEN(QueryStr))) / 1000)

      IF sec < 60 THEN Elapsed = "00:" & RIGHT$("0"+STR$(Sec),2)

      IF sec > 59 THEN
       mins = INT(sec / 60)
       sec = sec - (mins * 60)
       Elapsed = RIGHT$("0"+STR$(Mins),2) & ":" & RIGHT$("0"+STR$(Sec),2)
      END IF
     END FUNCTION
'-------------- end code ----------------

'The code above you use in case you send the complete file not parsed
'to the MCI (the MCI functions as the sequencer). In case you parse
'the whole file, you know the time from you timerfunction.

'And it is also possible to send a single message, like controllers,
'and note on and note off messages etc... You may try following code,
'just copy and paste into your code-editor and run:

'-------------- start code -------------------
     DECLARE FUNCTION midiOutShortMsg LIB "winmm.dll" ALIAS "midiOutShortMsg" _
      (hMidiOut AS LONG, dwMsg AS LONG) AS LONG
     DECLARE FUNCTION midiOutClose LIB "winmm.dll" ALIAS "midiOutClose" _
      (hMidiOut AS LONG) AS LONG
     DECLARE FUNCTION midiOutOpen LIB "winmm.dll" ALIAS "midiOutOpen" _
      (byref lphMidiOut AS LONG, uDeviceID AS LONG, dwCallback_
      AS LONG, dwInstance AS LONG, dwFlags AS LONG) AS LONG
     DECLARE FUNCTION packdword (i1 AS INTEGER, i2 AS INTEGER, i3 AS INTEGER, i4 AS INTEGER) AS LONG

     DECLARE SUB sendmsg

     DIM hmidiout AS LONG
     DIM device AS INTEGER
     device = 0
' change this value to play the notes with another device
' if there are any

     CREATE Form AS QFORM
      CAPTION = "MCI test, send arpeggio"
      Width = 246
      Height = 124
      Center
      CREATE Button1 AS QBUTTON
       CAPTION = "Send message to MCI"
       Left = 32
       Top = 40
       Width = 171
       Onclick = sendmsg
      END CREATE
      CREATE led AS QPANEL
       top = 80
       left = 32
       width = 16
       height = 8
       COLOR = &h000040
      END CREATE
      CREATE label1 AS QLABEL
       top = 76
       left = 50
       CAPTION = "Sending message"
      END CREATE
     END CREATE

     SUB sendmsg
      led.COLOR = &h0000ff
      midiOutOpen hMidiOut, device, 0, 0, 0
'open MCI

      FOR x = 1 TO 16
       DOEVENTS
       midiOutShortMsg hMidiOut, packdword(0, 100, 64+x, &h90)
'message looks as this:
'0 = 4th byte - not needed here
'100 = velocity (= 2nd data byte)
'64+x = note value (= 1st data byte)
'&h90 = status byte (= note on in this case)
       SLEEP 0.2
       midiOutShortMsg hMidiOut, packdword(0, 0, 64+x, &h90)
'this message has to be send to stop the notes from hanging
'same as before, only with velocity = 0
'This makes it a note off command
      NEXT

      midiOutClose hMidiOut
      led.COLOR = &h000040
     END SUB

     FUNCTION packdword (i1 AS INTEGER, i2 AS INTEGER, i3 AS INTEGER, i4 AS INTEGER) AS LONG
      packdword = i2 * &H10000 + i3 * &H100 + i4
'this function packs your message into one hex number,
'ready to send to the MCI
     END FUNCTION

     Form.SHOWMODAL
'----------------- end code ------------------

'But... (yes there is one), if you send a file to the MCI using
'the "play" command (an unparsed file), you won't be able to send
'messages to the device, as it is then already in use.
掌柜推荐
 
 
¥860.00 ·
 
 
¥900.00 ·
 
 
¥810.00 ·
 
 
¥317.00 ·
 
 
¥1,370.00 ·
 
 
¥660.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-10-28 19:59:26