dialog alarm {
  title "OzlemCafe mIRC Alarm"
  size -1 -1 250 150

  text "Alarm Zamani:", 1, 25 5 90 12
  edit "", 2, 115 3 25 20
  edit "", 3, 145 3 25 20
  radio "AM", 13, 175 3 40 14, group 
  radio "PM", 14, 175 17 40 14, 
  ;edit "", 5, 125 3 25 20
  text "s   :   d", 6, 124 22 40 14
  check "Yukselerek cal", 7, 5 57 90 14, 
  button "Ses Dosyasi", 8, 5 30 70 20, 
  check "Ses Tekrari", 9, 106 57 75 14, 
  button "Dur", 11, 20 120 50 20, 
  button "Basla", 12, 100 120 50 20, ok 
  button "Kapat", 10, 180 120 50 20, cancel 
  ;button "", 13, 0 0 0 0
  text "Alarm Mesaji"19, 85 77 235 12
  edit "" 775, 5 90 235 20, autohs

}
on *:DIALOG:alarm:*:*:{
  if ($devent == init) {
    if ($alarm.ri(Alarm,AmPm) == $null) { alarm.wi Alarm AmPm AM | did -c alarm 13 } | else { if ($alarm.ri(Alarm,AmPm) == AM) { did -c alarm 13 } | else { did -c alarm 14 } }
    if ($alarm.ri(Alarm,Hour) == $null) { alarm.wi Alarm Hour 12 | did -ra alarm 2 12 } | else { did -ra alarm 2 $alarm.ri(Alarm,Hour) } 
    if ($alarm.ri(Alarm,Minute) == $null) { alarm.wi Alarm Minute 00 | did -ra alarm 3 00 } | else { did -ra alarm 3 $alarm.ri(Alarm,Minute) } 
    if ($alarm.ri(Alarm,Ramping) == $null) { alarm.wi Alarm Ramping Off | did -u alarm 7 } 
    if ($alarm.ri(Alarm,Ramping) == Off) { alarm.wi Alarm Ramping Off | did -u alarm 7 } | else { did -c alarm 7 } 
    if ($alarm.ri(Alarm,Loop) == $null) { alarm.wi Alarm Loop Off | did -u alarm 9 } 
    if ($alarm.ri(Alarm,Loop) == Off) { alarm.wi Alarm Loop Off | did -u alarm 9 } | else { did -c alarm 9 } 
    did -a alarm 775 %uyarimsg  
  }
  if ($devent == sclick) { 
    if ($did == 7) { if ($did(7).state == 1) { alarm.wi Alarm Ramping On } | else { alarm.wi Alarm Ramping Off } }
    if ($did == 8) { alarm.wi Alarm Sound $$sfile($mircdirsounds\*.mp3,Select a file,Open) } 
    if ($did == 9) { if ($did(9).state == 1) { alarm.wi Alarm Loop On } | else { alarm.wi Alarm Loop Off } }
    if ($did == 11) { alarm.stop }
    if ($did == 12) { alarm.start }
    ;if ($did == 13) { $stdiag(m,help) | did -c help 1 }
    if ($did == 13) { alarm.wi Alarm AmPm AM } 
    if ($did == 14) { alarm.wi Alarm AmPm PM } 
  }
  if ($devent == edit) { 
    if ($did == 2) { 
      if (($did(2).text isnum) && ($did(2).text < 13) && ($did(2).text > 0)) { alarm.wi Alarm Hour $did(2).text }
      else { error You must specify a number } 
    } 
    if ($did == 3) { 
      if (($did(3).text isnum) && ($did(3).text < 60)) { alarm.wi Alarm Minute $did(3).text }
      else { error You must specify a number } 
    } 
    if ($did == 5) { if ($did(5).text isnum) { alarm.wi Alarm Second $did(5).text } | else { error You must specify a number } } 
  }
  if ($did == 775) { set %uyarimsg $did(775) } 
}
alias alarm.start {
  if (!$isfile($alarm.ri(Alarm,Sound))) { return $input(The file: $crlf $alarm.ri(Alarm,Sound) $crlf Ses dosyasi bulunamadi) | goto end }
  else { 
    var %hour $alarm.ri(Alarm,Hour)
    var %ampm $alarm.ri(Alarm,AmPm)
    if (%ampm == AM) { if ($alarm.ri(Alarm,Hour) == 12) { var %realhour 00 } | else { var %realhour $alarm.ri(Alarm,Hour) } }
    if (%ampm == PM) { if ($alarm.ri(Alarm,Hour) == 12) { var %realhour 12 } | else { var %realhour $calc( [ $alarm.ri(Alarm,Hour) ] + 12) } }
    .timeralarm -o $+(%realhour,:,$alarm.ri(Alarm,Minute)) 1 1 alarm.sound
  }
  :end

}
alias alarm.stop { 
  .timeralarm off
  if ($timer(alarm.ramp) !== $null) { .timeralarm.ramp off } 
  splay stop
}
alias alarm.sound { 
  $stdiag(mdr,alarm) 
  splay $+(",$alarm.ri(Alarm,Sound),")
  if ($alarm.ri(Alarm,Ramping) == On) { vol -v 0 | .timeralarm.ramp 0 5 alarm.ramp }
  uyari
}
alias alarm.ramp { 
  if ($vol(master) !== 65536) { vol -v $calc($vol(master) + 1310.7) | goto end } | else { goto vol2 } 
  :vol2
  if ($vol(wave) !== 65535) { vol -w $calc($vol(wave) + 1310.7) | goto end } | else { goto end } 
  :end
  if (($vol(master) == 65535) && ($vol(wave) == 65535)) { .timeralarm.ramp off } 
}
on *:WAVEEND:{ 
  if ($filename == $alarm.ri(Alarm,Sound)) { 
    if ($alarm.ri(Alarm,Loop) == On) { .splay $+(",$alarm.ri(Alarm,Sound),") } 
  }
}
on *:MP3END:{ 
  if ($filename == $alarm.ri(Alarm,Sound)) { 
    if ($alarm.ri(Alarm,Loop) == On) { .splay $+(",$alarm.ri(Alarm,Sound),") } 
  }
}
alias alarm { dialog -m alarm alarm }


alias -l alarm.wi { writeini $+(",$scriptdir,settings.ini,") $1 $2 $3- }
alias -l alarm.ri { return $readini($+(",$scriptdir,settings.ini,"),$1,$2) }


alias uyari { dialog -m uyari uyari }
dialog Uyari {
  size -1 -1 300 128
  title "OzlemCafe mIRC Alarm"
  box "Alarm",1, 5 5 290 60
  text %uyarimsg, 701,10 30 350 300,
  button "Dur",11, 32 80 100 25,  
  button "Kapat",12, 165 80 100 25, ok  
}
on *:DIALOG:uyari:*:*:{
  if ($devent == sclick) { 
    if ($did == 11) { alarm.stop }
  }
}
