alias alarm { dialog -m alarm alarm }
dialog alarm {
  title " Будильник"
  size 450 300 129 175
  option pixels
  icon $mircdirPsyScp.ico, 0
  edit "", 2, 23 21 25 18
  edit "", 3, 70 21 25 18
  text "Звуковой файл:", 7, 12 104 81 16
  button "Выбрать", 8, 27 125 52 18
  button "Стоп", 11, 62 59 50 18
  button "Запуск", 12, 8 59 50 18
  box "Время сигнала", 4, 12 6 95 43
  box "", 5, 4 -2 118 169
}

on *:DIALOG:alarm:*:*:{
  if ($devent == init) {
    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 ($devent == sclick) { 
    if ($did == 8) { alarm.wi Alarm Sound $$sfile($mircdirmp3\*.mp3,Select a file,Open) } 
    if ($did == 11) { alarm.stop }
    if ($did == 12) { alarm.start }
  }
  if ($devent == edit) { 
    if ($did == 2) { 
      if ($did(2).text isnum) { alarm.wi Alarm Hour $did(2).text }
      else { } 
    } 
    if ($did == 3) { 
      if (($did(3).text isnum) && ($did(3).text < 60)) { alarm.wi Alarm Minute $did(3).text }
      else { } 
    } 
    if ($did == 5) { if ($did(5).text isnum) { alarm.wi Alarm Second $did(5).text } | else { } } 
  }
}
alias alarm.start {
  if (!$isfile($alarm.ri(Alarm,Sound))) { return $input(Звуковой файл $crlf $alarm.ri(Alarm,Sound) $crlf не сушествует,oh,Error) | goto end }
  else { .timeralarm -o $calc($alarm.ri(Alarm,Hour)) $+ : $+ $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 { 
  dialog -mdr alarm alarm
  splay $+(",$alarm.ri(Alarm,Sound),")
}

on *:WAVEEND:{ 
  if ($filename == $alarm.ri(Alarm,Sound)) {
  }
}
on *:MP3END:{ 
  if ($filename == $alarm.ri(Alarm,Sound)) { 
    if ($alarm.ri(Alarm,Loop) == On) { .splay $+(",$alarm.ri(Alarm,Sound),") } 
  }
}

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