初めに
ポモドーロタイマーは一般的に「25分+5分」ですが、自分にはちょっと短いかなと思っていました。そこで「30分+10分」のものを自作してみました。
「もっとこうしたらいいんじゃない」というところがあったらぜひ教えてください。
コード
- OSはmacOSです
- 音源は主にこちらからダウンロードしました
-
afplay
というコマンドを使うと、mp3ファイルをコマンドラインで再生できるので、これを使いました
# include <stdio.h>
# include <unistd.h>
# include <stdlib.h>
/*
A "pomodoro" is a set of a working session and a short break.
And we define a "tomato" as a set of several pomodoros. We put a long break between two tomatoes.
But we don't put a short break at the end of a tomato.
*/
void work(double t /* min */)
{
system("afplay ~/Downloads/「開始します」.mp3 && afplay ~/Downloads/「がんばりましょう」.mp3");
printf("work start\n");
sleep(t * 60 /* seconds */);
printf("work end\n");
system("afplay ~/Downloads/warning1.mp3 && afplay ~/Downloads/「そこまで」.mp3");
}
void short_break(double t /* min */)
{
system("afplay ~/Downloads/「これより10分間の休憩となります」.mp3");
printf("short break start\n");
usleep(t * 3 / 4 * 60 * 1000000 /* micro s */);
system("afplay ~/Downloads/「始まるよ~」.mp3");
usleep(t * 1 / 4 * 60 * 1000000 /* micro s */);
printf("short break end\n");
}
void long_break(double t /* min */)
{
system("afplay ~/Downloads/「頑張ったね」.mp3");
printf("long break start\n");
usleep(t * 3 / 4 * 60 * 1000000 /* micro s */);
system("afplay ~/Downloads/「始まるよ~」.mp3");
usleep(t * 1 / 4 * 60 * 1000000 /* micro s */);
printf("long brek end\n");
}
int main()
{
int n_pomodoro = 3; // in one tomato
int n_tomato = 3;
double t_work = 30; // min
double t_short_break = 10; // min
double t_long_break = 30; // min
for (int i = 1; i <= n_tomato; i++)
{
for (int j = 1; j <= n_pomodoro; j++)
{
printf("%d-th tomato, %d-th pomodoro\n", i, j);
if (j == n_pomodoro)
{ // if the pomodoro is the last one in a tomato
work(t_work);
}
else
{
work(t_work);
short_break(t_short_break);
}
}
long_break(t_long_break);
}
return 0;
}