Skip to content
Browse files

First commit

  • Loading branch information...
0 parents commit d3c84fcb3851fd071fef4cb545ad4d93542967a8 n ddrylliog committed Oct 15, 2009
Showing with 61 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +7 −0 README
  3. +51 −0 alarmoo.ooc
3 .gitignore
@@ -0,0 +1,3 @@
+ooc_tmp
+*.[oa]
+alarmoo
7 README
@@ -0,0 +1,7 @@
+alarmoo is a cool alarm clock program which launches mplayer at the time you tell it, with the music you tell it
+
+e.g.
+
+alarmoo 07 15 "Wake Up, Lazy Geek - Monosong Ultra.ogg"
+
+To compile it, just type "ooc alarmoo"
51 alarmoo.ooc
@@ -0,0 +1,51 @@
+import structs/[Array, ArrayList], os/Process, os/Time
+
+AlarmClock: class {
+
+ cmd: ArrayList<String>
+
+ init: func (=cmd) {
+ cmd add(0, "mplayer")
+ }
+
+ ring: func -> Int {
+ SubProcess new(cmd data) execute()
+ }
+
+}
+
+main: func (args: Array<String>) {
+
+ if(args size() <= 3) {
+ printf("Syntax: %s hour min file.mp3 [file2.mp3 ...]\nNote: hour must be in 24H format\n", argv[0])
+ exit(0)
+ }
+
+ hour := args[1] toInt()
+ min := args[2] toInt()
+
+ files := ArrayList<String> new()
+ for(i in 3..args size())
+ files += args[i]
+
+ if(hour < 0 || hour >= 24) {
+ "Hour must be in 24H format, between 0 and 23\n" println()
+ exit(1)
+ }
+
+ if(min < 0 || min >= 59) {
+ "Min must be between 0 and 23" println()
+ exit(1)
+ }
+
+ clock := AlarmClock new(files)
+
+ target := hour * 60 + min;
+ while(Time hour() * 60 + Time min() < target) {
+ printf("Time: %02d:%02d:%02d %d\t\tTarget: %02d:%02d %d\n", Time hour(), Time min(), Time sec(), Time hour() * 60 + Time min(), hour, min, target)
+ Time sleepSec(1)
+ }
+ printf("Time: %02d:%02d:%02d\t\tTarget: %02d:%02d reached! Ringing \n", Time hour(), Time min(), Time sec(), hour, min);
+
+ clock ring()
+}

0 comments on commit d3c84fc

Please sign in to comment.
Something went wrong with that request. Please try again.