|
@@ -1,6 +1,6 @@
|
|
|
#rem
|
|
|
|
|
|
-Simple music demo.
|
|
|
+Simple music demo, with timed lyrics
|
|
|
|
|
|
Note: PlayMusic path must be a file system path so ths wont work on android yet.
|
|
|
|
|
@@ -19,10 +19,14 @@ Class MyWindow Extends Window
|
|
|
|
|
|
Field _channel:Channel
|
|
|
|
|
|
+ Field lyrics:TimedLyrics
|
|
|
+
|
|
|
Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )
|
|
|
|
|
|
Super.New( title,width,height,flags )
|
|
|
|
|
|
+ lyrics = New TimedLyrics
|
|
|
+
|
|
|
StartMusic()
|
|
|
End
|
|
|
|
|
@@ -47,6 +51,8 @@ Class MyWindow Extends Window
|
|
|
(_channel ? ", Sample="+_channel.PlayheadSample+", Time="+_channel.PlayheadTime Else ""),
|
|
|
0,0 )
|
|
|
|
|
|
+ If _channel lyrics.Render(canvas,_channel.PlayheadTime,Width/2,Height/2)
|
|
|
+
|
|
|
'Stop/Start?
|
|
|
If Keyboard.KeyHit( Key.Enter ) Or Mouse.ButtonHit( MouseButton.Left )
|
|
|
If _channel
|
|
@@ -76,3 +82,58 @@ Function Main()
|
|
|
|
|
|
App.Run()
|
|
|
End
|
|
|
+
|
|
|
+Class TimedText
|
|
|
+ Field time:Float
|
|
|
+ Field text:String
|
|
|
+
|
|
|
+ Method New(time:Float,text:String)
|
|
|
+ Self.time = time
|
|
|
+ Self.text = text
|
|
|
+ End
|
|
|
+
|
|
|
+End
|
|
|
+
|
|
|
+Class TimedLyrics
|
|
|
+
|
|
|
+ Field _lyr:= New Stack<TimedText>
|
|
|
+
|
|
|
+
|
|
|
+ Method New ()
|
|
|
+
|
|
|
+ _lyr.Add(New TimedText(2,"Back in black"))
|
|
|
+ _lyr.Add(New TimedText(3.3,"I hit the sack"))
|
|
|
+ _lyr.Add(New TimedText(4.7,"I've been too long I'm glad to be back"))
|
|
|
+ _lyr.Add(New TimedText(7,"Yes, I'm let loose"))
|
|
|
+ _lyr.Add(New TimedText(8.5,"From the noose"))
|
|
|
+ _lyr.Add(New TimedText(10,"That's kept me hanging about"))
|
|
|
+ _lyr.Add(New TimedText(12.5,"I've been looking at the sky"))
|
|
|
+ _lyr.Add(New TimedText(13.2,"'Cause it's gettin' me high"))
|
|
|
+ _lyr.Add(New TimedText(15,"Forget the hearse 'cause I never die"))
|
|
|
+ _lyr.Add(New TimedText(17,"I got nine lives"))
|
|
|
+ _lyr.Add(New TimedText(19.3,"Cat's eyes"))
|
|
|
+ _lyr.Add(New TimedText(20.5,"Abusin' every one of them and running wild"))
|
|
|
+ End
|
|
|
+
|
|
|
+ Method FindText:String (time:Float)
|
|
|
+ Local bestmatch:String
|
|
|
+ For Local tt:= Eachin _lyr
|
|
|
+ If time>=tt.time
|
|
|
+ bestmatch = tt.text
|
|
|
+ Endif
|
|
|
+ Next
|
|
|
+
|
|
|
+ Return bestmatch
|
|
|
+ End
|
|
|
+
|
|
|
+
|
|
|
+ Method Render(canvas:Canvas,time:Float,x:Int,y:Int)
|
|
|
+
|
|
|
+
|
|
|
+ canvas.DrawText(FindText(time),x,y,0.5,0.5)
|
|
|
+
|
|
|
+
|
|
|
+ End
|
|
|
+
|
|
|
+
|
|
|
+End
|