Project

General

Profile

libaudcore.output.cc.patch

Jim Turner, December 10, 2015 08:23

View differences:

output.cc.eqonly 2015-12-09 00:39:22.084886076 -0600
18 18
 */
19 19

  
20 20
#include "output.h"
21

  
21
#include <sys/stat.h>
22 22
#include <math.h>
23 23
#include <pthread.h>
24 24
#include <stdlib.h>
25 25
#include <string.h>
26

  
26
#include "audstrings.h"
27 27
#include "equalizer.h"
28 28
#include "internal.h"
29 29
#include "plugin.h"
......
76 76
#define SIGNAL_MINOR pthread_cond_broadcast (& cond_minor)
77 77
#define WAIT_MINOR pthread_cond_wait (& cond_minor, & mutex_minor)
78 78

  
79
static bool s_songautoeq; /* JWT:ADDED TO ALLOW SONG/STREAM-SPECIFIC EQUALIZATION. */
80
#ifdef _WINDOWS
81
    static const char * path_sep = "\\";
82
#endif
83
#ifndef _WINDOWS
84
    static const char * path_sep = "/";
85
#endif
86

  
79 87
static OutputPlugin * cop; /* current (primary) output plugin */
80 88
static OutputPlugin * sop; /* secondary output plugin */
81 89

  
......
353 361
    write_output_raw (effect_finish (buffer1, end_of_playlist));
354 362
}
355 363

  
364
/* JWT:NEXT 2 FUNCTIONS ADDED TO ALLOW SONG/STREAM-SPECIFIC EQUALIZATION. */
365
/* JWT:FIXME:I WANTED TO USE filename_build() BUT COULD NEVER GET IT TO WORK?! */
366
static void do_save_eq_file (StringBuf filename)
367
{
368
    EqualizerPreset preset;
369
    aud_eq_update_preset (preset);
370

  
371
    VFSFile file (filename, "w");
372
    if (file)
373
        aud_save_preset_file (preset, file);
374
}
375

  
376
static void do_load_eq_file (StringBuf filename, bool load_songautoeq)
377
{
378
    EqualizerPreset preset;
379
    bool havesongeqfile = true;
380

  
381
    const char * filenamechar = (const char *)filename + 7;
382
    if (filenamechar)
383
    {
384
    	   struct stat statbuf;
385
    	   if (stat (filenamechar, &statbuf))
386
    	       havesongeqfile = false;   /* SONG HAS NO SONG-SPECIFIC PRESET FILE, SO DO NOTHING */
387
    }
388
    if (havesongeqfile)
389
    {
390
        VFSFile file (filename, "r");
391
        if (file && aud_load_preset_file (preset, file))
392
        {
393
            /* JWT:IF LOADING SONG-SPECIFIC PRESETS AND WE DON'T HAVE SONG-SPECIFIC ONES IN EFFECT NOW, THEN SAVE
394
               THE CURRENT PRESETS OUT AS THE "DEFAULT" FOR LATER RESTORATION ON NEXT SONG W/O SONG-SPECIFIC PRESETS */
395
            if (load_songautoeq && ! s_songautoeq)
396
    	           do_save_eq_file (str_printf("%s%s%s%s", "file://",
397
    	                   aud_get_path (AudPath::UserDir), path_sep, "_nonauto.preset"));
398

  
399
            aud_eq_apply_preset (preset);   /* APPLY THE SONG-SPECIFIC PRESET FILE AND NOTE THAT WE DID THAT! */
400
            s_songautoeq = load_songautoeq;
401
        }
402
        else
403
            s_songautoeq = false;
404
    }
405
    else
406
        s_songautoeq = false;
407
}
408

  
356 409
bool output_open_audio (const String & filename, const Tuple & tuple,
357 410
 int format, int rate, int channels, int start_time)
358 411
{
412
    bool prev_songautoeq = aud_get_bool("audacious", "equalizer_songauto");
413
    s_songautoeq = prev_songautoeq;
359 414
    /* prevent division by zero */
360 415
    if (rate < 1 || channels < 1 || channels > AUD_MAX_CHANNELS)
361 416
        return false;
......
383 438
    in_frames = 0;
384 439

  
385 440
    setup_output ();
441
    /* JWT:NEXT CONDITION BLOCK ADDED TO ALLOW SONG/STREAM-SPECIFIC EQUALIZATION. */
442
    if (aud_get_bool (nullptr, "equalizer_autoload"))
443
    {
444
        const char * slash;
445
        const char * base;
446
        int ln = -1;
447
        slash = filename ? strrchr (filename, '/') : nullptr;
448
        base = slash ? slash + 1 : nullptr;
449
        if (slash && (!base || base[0] == '\0')) // FILENAME ENDS IN A "/"!
450
        {
451
            do
452
            {
453
                --slash;
454
                ++ln;
455
            } while (slash && slash > filename && slash[0] != '/');
456
            base = slash ? slash + 1 : nullptr;
457
            if (ln > 0)
458
                do_load_eq_file (str_printf("%s%s%s%.*s%s", "file://",
459
                        aud_get_path (AudPath::UserDir), path_sep, ln, base, ".preset"), true);
460
        }
461
        else if (base && base[0] != '\0' && strncmp (base, "-.", 2))
462
        	   do_load_eq_file (str_printf("%s%s%s%s%s", "file://",
463
        	           aud_get_path (AudPath::UserDir), path_sep, base, ".preset"), true);
464
    }
465
    else
466
        s_songautoeq = false;
467

  
468
    /* JWT:IF PREV. SONG LOADED IT'S OWN PRESETS, BUT THE CURRENT SONG DOES NOT HAVE IT'S OWN,
469
       THEN RESTORE THE "DEFAULT" (LAST KNOWN NON SONG-SPECIFIC) ONES */
470
    if (prev_songautoeq && !s_songautoeq)
471
        do_load_eq_file (str_printf("%s%s%s%s", "file://",
472
    	           aud_get_path (AudPath::UserDir), path_sep, "_nonauto.preset"), false);
386 473

  
387 474
    UNLOCK_ALL;
475

  
476
    aud_set_bool("audacious", "equalizer_songauto", s_songautoeq);
388 477
    return true;
389 478
}
390 479