Author Topic: Simple MCI example  (Read 1619 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Simple MCI example
« on: June 10, 2018, 04:40:32 AM »
Hello,

this is a simple example using mciSendString and a timer. At first, I wanted to create a banner, but now it is just a simple window even without scrollbars. It applies a very, very simple approach.

The necessary midi file I found on this website:
http://www.armory.com/~keeper/midiold.html

The song was written in 1965 by Tom Lehrer. It shows the dilemma humanity has faced since the Stone Age.

Roland

Code: OxygenBasic
  1. $ filename "Lyrics.exe"
  2.  
  3. 'uses rtl32
  4. 'uses rtl64
  5.  
  6. uses WinUtil
  7. 'uses console
  8.  
  9. % DS_MODALFRAME=128
  10. % GCLP_HBRBACKGROUND= -10
  11. % COLOR_3DFACE=15
  12.  
  13. extern lib "winmm.dll"
  14. ! mciSendString "mciSendStringA"    '4
  15. end extern
  16.  
  17. declare sub loadlyrics()
  18.  
  19. redim string lyrics[30]
  20. sys lbl[5]
  21.  
  22. loadlyrics()
  23.  
  24. sys hInstance=inst
  25. MainWindow 400,220, DS_MODALFRAME OR WS_POPUP OR WS_CAPTION OR WS_SYSMENU
  26.  
  27.  
  28. function WndProc(sys hwnd, uMsg, wParam, lParam) as sys callback
  29. string temp=space 256
  30. int unit, x
  31.  
  32.     select uMsg
  33.         case WM_CREATE
  34.             SetWindowText(hwnd, "Tom Lehrer - Who's next")
  35.            'Adjust color of MainWindow
  36.            SetClassLongPtr(hwnd,GCLP_HBRBACKGROUND, GetSysColorBrush(COLOR_3DFACE))
  37.                        
  38.             lbl[1]=CreateWindowEx(0,"static","",WS_CHILDWINDOW|WS_VISIBLE, 20, 30,360,25, hwnd,0,hinstance,0)
  39.             lbl[2]=CreateWindowEx(0,"static","",WS_CHILDWINDOW|WS_VISIBLE, 20, 55,360,25, hwnd,0,hinstance,0)
  40.             lbl[3]=CreateWindowEx(0,"static","",WS_CHILDWINDOW|WS_VISIBLE, 20, 80,360,25, hwnd,0,hinstance,0)
  41.             lbl[4]=CreateWindowEx(0,"static","",WS_CHILDWINDOW|WS_VISIBLE, 20,105,360,25, hwnd,0,hinstance,0)
  42.             lbl[5]=CreateWindowEx(0,"static","",WS_CHILDWINDOW|WS_VISIBLE, 20,130,360,25, hwnd,0,hinstance,0)
  43.        
  44.             mciSendString("open whonext.mid type sequencer alias whonext", 0, 0, 0)
  45.             mciSendString("status whonext length", temp, 256,0)
  46.             unit=val(temp)
  47.             if unit=0 then
  48.               mbox "Cannot open whonext.mid. Sorry!"
  49.               SendMessage(hwnd, WM_CLOSE,0,0)
  50.             end if  
  51.             if unit!=759 then
  52.               mbox "Wrong midi file. Sorry!"
  53.               SendMessage(hwnd, WM_CLOSE,0,0)
  54.             end if  
  55.  
  56.             mciSendString("play whonext", 0, 0, 0)
  57.  
  58.             SetTimer(hwnd,1000,10,0)
  59. /*
  60.         'check the position
  61.        case WM_LBUTTONDOWN
  62.             mciSendString("status whonext position", temp, 256,0)
  63.             unit=val(temp)
  64.             printl unit
  65. */
  66.         case WM_TIMER
  67.             mciSendString("status whonext position", temp, 256,0)
  68.             unit=val(temp)
  69.  
  70.             select unit
  71.             case >= 725 : SetWindowText(lbl[4],lyrics[30]) :  KillTimer(hwnd)
  72.             case >= 705 : SetWindowText(lbl[3],lyrics[29])            
  73.             case >= 692 : SetWindowText(lbl[2],lyrics[28])          
  74.             case >= 682         '6'
  75.              for x=1 to 5 : SetWindowText(lbl[x])="" : next            
  76.               SetWindowText(lbl[1],lyrics[27])            
  77.  
  78.             case >= 660 : SetWindowText(lbl[4],lyrics[26])          
  79.             case >= 636 : SetWindowText(lbl[3],lyrics[25])            
  80.             case >= 617 : SetWindowText(lbl[2],lyrics[24])            
  81.             case >= 596          '5'
  82.              for x=1 to 5 : SetWindowText(lbl[x])="" : next
  83.               SetWindowText(lbl[1],lyrics[23])
  84.            
  85.             case >= 572 : SetWindowText(lbl[5],lyrics[22])            
  86.             case >= 532 : SetWindowText(lbl[4],lyrics[21])            
  87.             case >= 510 : SetWindowText(lbl[3],lyrics[20])            
  88.             case >= 489 : SetWindowText(lbl[2],lyrics[19])            
  89.             case >= 461          '4b'
  90.              for x=1 to 5 : SetWindowText(lbl[x])="" : next
  91.               SetWindowText(lbl[1],lyrics[18])
  92.            
  93.             case >= 422 : SetWindowText(lbl[2],lyrics[17])            
  94.             case >= 379          '4a'
  95.              for x=1 to 5 : SetWindowText(lbl[x])="" : next
  96.               SetWindowText(lbl[1],lyrics[16])
  97.            
  98.             case >= 355 : SetWindowText(lbl[5],lyrics[15])            
  99.             case >= 336 : SetWindowText(lbl[4],lyrics[14])            
  100.             case >= 312 : SetWindowText(lbl[3],lyrics[13])            
  101.             case >= 291 : SetWindowText(lbl[2],lyrics[12])            
  102.             case >= 265          '3'
  103.              for x=1 to 5 : SetWindowText(lbl[x])="" : next
  104.               SetWindowText(lbl[1],lyrics[11])
  105.            
  106.             case >= 245 : SetWindowText(lbl[5],lyrics[10])            
  107.             case >= 228 : SetWindowText(lbl[4],lyrics[9])            
  108.             case >= 205 : SetWindowText(lbl[3],lyrics[8])            
  109.             case >= 185 : SetWindowText(lbl[2],lyrics[7])            
  110.             case >= 165          '2'
  111.              for x=1 to 5 : SetWindowText(lbl[x])="" : next
  112.               SetWindowText(lbl[1],lyrics[6])
  113.            
  114.             case >= 141 : SetWindowText(lbl[5],lyrics[5])            
  115.             case >= 121 : SetWindowText(lbl[4],lyrics[4])            
  116.             case >= 98  : SetWindowText(lbl[3],lyrics[3])            
  117.             case >= 80  : SetWindowText(lbl[2],lyrics[2])                        
  118.             case >= 59           '1'
  119.              SetWindowText(lbl[1],lyrics[1])
  120.             end select
  121.                        
  122.         case WM_CLOSE
  123.             'Close whonext.mid file and sequencer device
  124.            mciSendString("close whonext", 0, 0, 0)
  125.             KillTimer(hwnd)
  126.            
  127.             DestroyWindow(hwnd)
  128.        
  129.         case WM_DESTROY
  130.             PostQuitMessage(0)
  131.        
  132.         case else
  133.             return DefWindowProc(hwnd, uMsg, wParam, lParam)
  134.            
  135.     end select
  136.    
  137.     return 0
  138. end function
  139.  
  140. 'Tom Lehrer - Who's next (1965)
  141. sub loadlyrics()
  142. lyrics[]={
  143. "First we got the bomb, and that was good,",
  144. "'Cause we love peace and motherhood.",
  145. "Then Russia got the bomb, but that's okay,",
  146. "'Cause the balance of power's maintained that way.",
  147. "Who's next?",
  148.  
  149. "Then France got the bomb, but don't you grieve,",
  150. "'Cause they're on our side (I believe).",
  151. "China got the bomb, but have no fears,",
  152. "'Cause they can't wipe us out for a least five years.",
  153. "Who's next?",
  154.  
  155. "Japan will have its own device,",
  156. "Transistorized at half the price.",
  157. "South Africa wants two, that's right:",
  158. "One for the black and one for the white.",
  159. "Who's next?",
  160.  
  161. "Egypt's gonna get one too,",
  162. "Just to use on you-know-who.",
  163. "So Israel's getting tense,",
  164. "Wants one in self defense.",
  165. "The Lord's our shepherd says the psalm,",
  166. "But just in case, we better get a bomb.",
  167. "Who's next?",
  168.  
  169. "Luxembourg is next to go,",
  170. "And (who knows?) maybe Monaco.",
  171. "We'll try to stay serene and calm",
  172. "When Alabama gets the bomb.",
  173. "Who's next?",
  174. "Who's next?",
  175. "Who's next?",
  176. "Who's next??"
  177. }
  178. end sub
  179.  

Charles Pegge

  • Guest
Re: Simple MCI example
« Reply #1 on: June 10, 2018, 05:19:20 AM »
Many thanks, Roland.

I will include this in examples\sound\

Midi files are so compact!