Esempio n. 1
0
static void *alarm_fade(void *arg)
{
    fader *vols = (fader *)arg;
    guint i;
    gint v;
    gint inc, diff, adiff;

    /* lock */
    pthread_mutex_lock(&fader_lock);

    /* slide volume */
    /* the Kaspar Giger way of fading, check the current mixer volume and
     * increment from there so that if you have some other app lowering the
     * volume at the same time, the alarm plugin will not ignore it.  If you have
     * some other app increasing the volume, then it could get louder than you expect
     * though - because the loop does not recalculate the difference each time.
     */

    /* difference between the 2 volumes */
    diff = vols->end - vols->start;
    adiff = abs(diff);

    /* Are we going up or down? */
    if(diff < 0)
        inc = -1;
    else
        inc = 1;

    aud_drct_set_volume_main((gint)vols->start);
    //for(i=0;i<(vols->end - vols->start);i++)
    for(i=0;i<adiff;i++)
    {
        //threadsleep((gfloat)fading / (vols->end - vols->start));
        threadsleep((gfloat)fading / (gfloat)adiff);
        aud_drct_get_volume_main(&v);
        aud_drct_set_volume_main(v + inc);
    }
    /* Setting the volume to the end volume sort of defeats the point if having
     * the code in there to allow other apps to control volume too :)
     */
    //aud_drct_set_volume_main((gint)vols->end);

    /* and */
    pthread_mutex_unlock(&fader_lock);

    AUDDBG("volume = %f%%\n", (gdouble)vols->end);
    return 0;
}
Esempio n. 2
0
static void *alarm_stop_thread(void *args)
{
    gint currvol;
    fader fade_vols;
    alarm_thread_t f;

    AUDDBG("alarm_stop_thread\n");


    /* sleep for however long we are meant to be sleeping for until
     * its time to shut up
     */
    threadsleep(((stop_h * 60) + stop_m) * 60);

    AUDDBG("alarm_stop triggered\n");

    if (alarm_dialog)
        gtk_widget_destroy(alarm_dialog);

    aud_drct_get_volume_main(&currvol),

    /* fade back to zero */
    fade_vols.start = currvol;
    fade_vols.end = 0;

    /* The fader thread locks the fader_mutex now */
    f = alarm_thread_create(alarm_fade, &fade_vols, 0);

    pthread_join(f.tid, NULL);
    aud_drct_stop();

    /* might as well set the volume to something higher than zero so we
     * dont confuse the poor people who just woke up and cant work out why
     * theres no music playing when they press the little play button :)
     */
    aud_drct_set_volume_main(currvol);

    AUDDBG("alarm_stop done\n");
    return(NULL);
}
Esempio n. 3
0
/* the main alarm thread */
static gboolean alarm_timeout (void * unused)
{
    struct tm *currtime;
    time_t timenow;
    guint today;

    AUDDBG("Getting time\n");
    timenow = time(NULL);
    currtime = localtime(&timenow);
    today = currtime->tm_wday;
    AUDDBG("Today is %d\n", today);

    /* already went off? */
    if (timenow < play_start + 60)
        return TRUE;

    if(alarm_conf.day[today].flags & ALARM_OFF)
        return TRUE;
    else
    {
        /* set the alarm_h and alarm_m for today, if not default */
        if(!(alarm_conf.day[today].flags & ALARM_DEFAULT))
        {
            alarm_h = alarm_conf.day[today].hour;
            alarm_m = alarm_conf.day[today].min;
        }
        else
        {
            alarm_h = alarm_conf.default_hour;
            alarm_m = alarm_conf.default_min;
        }
    }

    AUDDBG("Alarm time is %d:%d (def: %d:%d)\n", alarm_h, alarm_m,
    alarm_conf.default_hour, alarm_conf.default_min);

    AUDDBG("Checking time (%d:%d)\n", currtime->tm_hour, currtime->tm_min);
    if((currtime->tm_hour != alarm_h) || (currtime->tm_min != alarm_m))
        return TRUE;

    if(cmd_on == TRUE)
    {
        char * cmdstr = aud_get_str ("alarm", "cmdstr");
        AUDDBG("Executing %s, cmd_on is true\n", cmdstr);
        if(system(cmdstr) == -1)
            AUDDBG("Executing %s failed\n",cmdstr);
        str_unref (cmdstr);
    }

    bool_t started = FALSE;

    char * playlist = aud_get_str ("alarm", "playlist");
    if (playlist[0])
    {
        aud_drct_pl_open (playlist);
        started = TRUE;
    }
    str_unref (playlist);

    if(fading)
    {
        fader fade_vols;

        AUDDBG("Fading is true\n");
        aud_drct_set_volume_main(quietvol);

        /* start playing */
        play_start = time(NULL);

        if (! started)
            aud_drct_play ();

        /* fade volume */
        fade_vols.start = quietvol;
        fade_vols.end = volume;

        //alarm_fade(quietvol, volume);
        alarm_thread_create(alarm_fade, &fade_vols, 0);
    }
    else
    {
        /* no fading */

        /* set volume */
        aud_drct_set_volume_main(volume);

        /* start playing */
        play_start = time(NULL);
        aud_drct_play();
    }

    if(alarm_conf.reminder_on == TRUE)
    {
        char * reminder_msg = aud_get_str ("alarm", "reminder_msg");
        GtkWidget *reminder_dialog;
        AUDDBG("Showing reminder '%s'\n", reminder_msg);

        reminder_dialog = (GtkWidget*) create_reminder_dialog(reminder_msg);
        gtk_widget_show_all(reminder_dialog);
        str_unref (reminder_msg);
    }

    /* bring up the wakeup call dialog if stop_on is set TRUE, this
     * has been moved to after making Audacious play so that it doesnt
     * get in the way for people with manual window placement turned on
     *
     * this means that the dialog doesnt get shown until the volume has
     * finished fading though !, so thats something else to fix
     */
    if(stop_on == TRUE)
    {
        alarm_dialog = create_alarm_dialog();

        AUDDBG("now starting stop thread\n");
        stop = alarm_thread_create(alarm_stop_thread, NULL, 0);
        AUDDBG("Created wakeup dialog and started stop thread\n");
    }

    return TRUE;
}
Esempio n. 4
0
/* handle keys */
gboolean handle_keyevent (EVENT event)
{
    gint current_volume, old_volume;
    static gint volume_static = 0;
    gboolean play, mute;

    /* playing or not */
    play = aud_drct_get_playing ();

    /* get current volume */
    aud_drct_get_volume_main (&current_volume);
    old_volume = current_volume;
    if (current_volume)
    {
        /* volume is not mute */
        mute = FALSE;
    } else {
        /* volume is mute */
        mute = TRUE;
    }

    /* mute the playback */
    if (event == EVENT_MUTE)
    {
        if (!mute)
        {
            volume_static = current_volume;
            aud_drct_set_volume_main (0);
            mute = TRUE;
        } else {
            aud_drct_set_volume_main (volume_static);
            mute = FALSE;
        }
        return TRUE;
    }

    /* decreace volume */
    if (event == EVENT_VOL_DOWN)
    {
        if (mute)
        {
            current_volume = old_volume;
            old_volume = 0;
            mute = FALSE;
        }

        if ((current_volume -= plugin_cfg.vol_decrement) < 0)
        {
            current_volume = 0;
        }

        if (current_volume != old_volume)
        {
            aud_drct_set_volume_main (current_volume);
        }

        old_volume = current_volume;
        return TRUE;
    }

    /* increase volume */
    if (event == EVENT_VOL_UP)
    {
        if (mute)
        {
            current_volume = old_volume;
            old_volume = 0;
            mute = FALSE;
        }

        if ((current_volume += plugin_cfg.vol_increment) > 100)
        {
            current_volume = 100;
        }

        if (current_volume != old_volume)
        {
            aud_drct_set_volume_main (current_volume);
        }

        old_volume = current_volume;
        return TRUE;
    }

    /* play */
    if (event == EVENT_PLAY)
    {
        aud_drct_play ();
        return TRUE;
    }

    /* pause */
    if (event == EVENT_PAUSE)
    {
        if (!play) aud_drct_play ();
        else aud_drct_pause ();

        return TRUE;
    }

    /* stop */
    if (event == EVENT_STOP)
    {
        aud_drct_stop ();
        return TRUE;
    }

    /* prev track */
    if (event == EVENT_PREV_TRACK)
    {
        aud_drct_pl_prev ();
        return TRUE;
    }

    /* next track */
    if (event == EVENT_NEXT_TRACK)
    {
        aud_drct_pl_next ();
        return TRUE;
    }

    /* forward */
    if (event == EVENT_FORWARD)
    {
        aud_drct_seek (aud_drct_get_time () + 5000);
        return TRUE;
    }

    /* backward */
    if (event == EVENT_BACKWARD)
    {
        gint time = aud_drct_get_time ();
        if (time > 5000) time -= 5000; /* Jump 5s back */
            else time = 0;
        aud_drct_seek (time);
        return TRUE;
    }

    /* Open Jump-To-File dialog */
    if (event == EVENT_JUMP_TO_FILE)
    {
        aud_interface_show_jump_to_track ();
        return TRUE;
    }

    /* Toggle Windows */
    if (event == EVENT_TOGGLE_WIN)
    {
        aud_interface_show (! (aud_interface_is_shown () && aud_interface_is_focused ()));
        return TRUE;
    }

    /* Show OSD through AOSD plugin*/
    if (event == EVENT_SHOW_AOSD)
    {
        hook_call("aosd toggle", NULL);
        return TRUE;
    }

    if (event == EVENT_TOGGLE_REPEAT)
    {
        aud_set_bool (NULL, "repeat", ! aud_get_bool (NULL, "repeat"));
        return TRUE;
    }

    if (event == EVENT_TOGGLE_SHUFFLE)
    {
        aud_set_bool (NULL, "shuffle", ! aud_get_bool (NULL, "shuffle"));
        return TRUE;
    }

    if (event == EVENT_TOGGLE_STOP)
    {
        aud_set_bool (NULL, "stop_after_current_song", ! aud_get_bool (NULL, "stop_after_current_song"));
        return TRUE;
    }

    if (event == EVENT_RAISE)
    {
        aud_interface_show (TRUE);
        return TRUE;
    }

    return FALSE;
}
Esempio n. 5
0
static void volume_down (void)
{
    int vol = 0;
    aud_drct_get_volume_main (& vol);
    aud_drct_set_volume_main (vol - 5);
}
Esempio n. 6
0
static void volume_up (void)
{
    int vol = 0;
    aud_drct_get_volume_main (& vol);
    aud_drct_set_volume_main (vol + 5);
}
Esempio n. 7
0
static gboolean lirc_input_callback (GIOChannel * source, GIOCondition condition, void * data)
{
    char *code;
    char *c;
    gint playlist_time, playlist_pos, output_time, v;
    int ret;
    char *ptr;
    gint balance;
#if 0
    gboolean show_pl;
#endif
    int n;
    gchar *utf8_title_markup;

    while ((ret = lirc_nextcode (&code)) == 0 && code != NULL)
    {
        while ((ret = lirc_code2char (config, code, &c)) == 0 && c != NULL)
        {
            if (strcasecmp ("PLAY", c) == 0)
                aud_drct_play ();
            else if (strcasecmp ("STOP", c) == 0)
                aud_drct_stop ();
            else if (strcasecmp ("PAUSE", c) == 0)
                aud_drct_pause ();
            else if (strcasecmp ("PLAYPAUSE", c) == 0)
                aud_drct_play_pause ();
            else if (strncasecmp ("NEXT", c, 4) == 0)
            {
                ptr = c + 4;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);

                if (n <= 0)
                    n = 1;
                for (; n > 0; n--)
                {
                    aud_drct_pl_next ();
                }
            }
            else if (strncasecmp ("PREV", c, 4) == 0)
            {
                ptr = c + 4;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);

                if (n <= 0)
                    n = 1;
                for (; n > 0; n--)
                {
                    aud_drct_pl_prev ();
                }
            }
            else if (strcasecmp ("SHUFFLE", c) == 0)
                aud_set_bool (NULL, "shuffle", ! aud_get_bool (NULL, "shuffle"));
            else if (strcasecmp ("REPEAT", c) == 0)
                aud_set_bool (NULL, "repeat", ! aud_get_bool (NULL, "repeat"));
            else if (strncasecmp ("FWD", c, 3) == 0)
            {
                ptr = c + 3;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr) * 1000;

                if (n <= 0)
                    n = 5000;
                output_time = aud_drct_get_time ();

                int playlist = aud_playlist_get_active ();
                playlist_pos = aud_playlist_get_position (playlist);
                playlist_time =
                    aud_playlist_entry_get_length (playlist, playlist_pos,
                                                   FALSE);
                if (playlist_time - output_time < n)
                    output_time = playlist_time - n;
                aud_drct_seek (output_time + n);
            }
            else if (strncasecmp ("BWD", c, 3) == 0)
            {
                ptr = c + 3;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr) * 1000;

                if (n <= 0)
                    n = 5000;
                output_time = aud_drct_get_time ();
                if (output_time < n)
                    output_time = n;
                aud_drct_seek (output_time - n);
            }
            else if (strncasecmp ("VOL_UP", c, 6) == 0)
            {
                ptr = c + 6;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);
                if (n <= 0)
                    n = 5;

                aud_drct_get_volume_main (&v);
                if (v > (100 - n))
                    v = 100 - n;
                aud_drct_set_volume_main (v + n);
            }
            else if (strncasecmp ("VOL_DOWN", c, 8) == 0)
            {
                ptr = c + 8;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);
                if (n <= 0)
                    n = 5;

                aud_drct_get_volume_main (&v);
                if (v < n)
                    v = n;
                aud_drct_set_volume_main (v - n);
            }
            else if (strcasecmp ("QUIT", c) == 0)
            {
                aud_drct_quit ();
            }
            else if (strcasecmp ("MUTE", c) == 0)
            {
                if (mute == 0)
                {
                    mute = 1;
                    /* store the master volume so
                       we can restore it on unmute. */
                    aud_drct_get_volume_main (&mute_vol);
                    aud_drct_set_volume_main (0);
                }
                else
                {
                    mute = 0;
                    aud_drct_set_volume_main (mute_vol);
                }
            }
            else if (strncasecmp ("BAL_LEFT", c, 8) == 0)
            {
                ptr = c + 8;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);
                if (n <= 0)
                    n = 5;

                aud_drct_get_volume_balance (&balance);
                balance -= n;
                if (balance < -100)
                    balance = -100;
                aud_drct_set_volume_balance (balance);
            }
            else if (strncasecmp ("BAL_RIGHT", c, 9) == 0)
            {
                ptr = c + 9;
                while (isspace (*ptr))
                    ptr++;
                n = atoi (ptr);
                if (n <= 0)
                    n = 5;

                aud_drct_get_volume_balance (&balance);
                balance += n;
                if (balance > 100)
                    balance = 100;
                aud_drct_set_volume_balance (balance);
            }
            else if (strcasecmp ("BAL_CENTER", c) == 0)
            {
                balance = 0;
                aud_drct_set_volume_balance (balance);
            }
            else if (strcasecmp ("LIST", c) == 0)
            {
#if 0
                show_pl = aud_drct_pl_win_is_visible ();
                show_pl = (show_pl) ? 0 : 1;
                aud_drct_pl_win_toggle (show_pl);
#endif
            }
            else if (strcasecmp ("PLAYLIST_CLEAR", c) == 0)
            {
                aud_drct_stop ();
                int playlist = aud_playlist_get_active ();
                aud_playlist_entry_delete (playlist, 0,
                                           aud_playlist_entry_count
                                           (playlist));
            }
            else if (strncasecmp ("PLAYLIST_ADD ", c, 13) == 0)
            {
                aud_drct_pl_add (c + 13, -1);
            }
            else if ((strlen (c) == 1) && ((*c >= '0') || (*c <= '9')))
            {
                if (track_no_pos < 63)
                {
                    if (tid)
                        g_source_remove (tid);
                    track_no[track_no_pos++] = *c;
                    track_no[track_no_pos] = 0;
                    tid = g_timeout_add (1500, jump_to, NULL);
                    utf8_title_markup = g_markup_printf_escaped ("%s", track_no);
                    hook_call ("aosd toggle", utf8_title_markup);
                }
            }
            else
            {
                fprintf (stderr, _("%s: unknown command \"%s\"\n"),
                         plugin_name, c);
            }
        }
        free (code);
        if (ret == -1)
            break;
    }
    if (ret == -1)
    {
        /* something went badly wrong */
        fprintf (stderr, _("%s: disconnected from LIRC\n"), plugin_name);
        cleanup ();
        if (aud_get_bool ("lirc", "enable_reconnect"))
        {
            int reconnect_timeout = aud_get_int ("lirc", "reconnect_timeout");
            fprintf (stderr,
                     _("%s: will try reconnect every %d seconds...\n"),
                     plugin_name, reconnect_timeout);
            g_timeout_add (1000 * reconnect_timeout, reconnect_lirc, NULL);
        }
    }

    return TRUE;
}
Esempio n. 8
0
static void volume_changed (GObject * object)
{
    double vol;
    g_object_get (object, "volume", & vol, NULL);
    aud_drct_set_volume_main (round (vol * 100));
}
Esempio n. 9
0
static void
on_media_player_key_pressed (DBusGProxy *proxy, const gchar *application, const gchar *key)
{
    if (strcmp ("Audacious", application) == 0) {
        gint current_volume /* , old_volume */ ;
        static gint volume_static = 0;
        gboolean mute;

        /* get current volume */
        aud_drct_get_volume_main (&current_volume);
        /* old_volume = current_volume; */
        if (current_volume)
        {
            /* volume is not mute */
            mute = FALSE;
        } else {
            /* volume is mute */
            mute = TRUE;
        }

        /* mute the playback */
        if (strcmp ("Mute", key) == 0)
        {
            if (!mute)
            {
                volume_static = current_volume;
                aud_drct_set_volume_main (0);
                mute = TRUE;
            } else {
                aud_drct_set_volume_main (volume_static);
                mute = FALSE;
            }
            return;
        }

        /* decreace volume */
/*      if ((keycode == plugin_cfg.vol_down) && (state == plugin_cfg.vol_down_mask))
        {
            if (mute)
            {
                current_volume = old_volume;
                old_volume = 0;
                mute = FALSE;
            }

            if ((current_volume -= plugin_cfg.vol_decrement) < 0)
            {
                current_volume = 0;
            }

            if (current_volume != old_volume)
            {
                xmms_remote_set_main_volume (audacioushotkey.xmms_session,
                 current_volume);
            }

            old_volume = current_volume;
            return TRUE;
        }*/

        /* increase volume */
/*      if ((keycode == plugin_cfg.vol_up) && (state == plugin_cfg.vol_up_mask))
        {
            if (mute)
            {
                current_volume = old_volume;
                old_volume = 0;
                mute = FALSE;
            }

            if ((current_volume += plugin_cfg.vol_increment) > 100)
            {
                current_volume = 100;
            }

            if (current_volume != old_volume)
            {
                xmms_remote_set_main_volume (audacioushotkey.xmms_session,
                 current_volume);
            }

            old_volume = current_volume;
            return TRUE;
        }*/

        /* play or pause */
        if (strcmp ("Play", key) == 0 || strcmp ("Pause", key) == 0)
        {
            aud_drct_play_pause ();
            return;
        }

        /* stop */
        if (strcmp ("Stop", key) == 0)
        {
            aud_drct_stop ();
            return;
        }

        /* prev track */
        if (strcmp ("Previous", key) == 0)
        {
            aud_drct_pl_prev ();
            return;
        }

        /* next track */
        if (strcmp ("Next", key) == 0)
        {
            aud_drct_pl_next ();
            return;
        }
    }
}