version: 2.0

jobs:
  archlinux:
    docker:
      - image: archlinux:latest
        auth:
          username: wellingtonwallace
          password: $DOCKERHUB_PASSWORD
    environment:
      LANG: C
      DISPLAY: :10
      G_MESSAGES_DEBUG: easyeffects
    steps:
      - run: date +%F > /tmp/date
      - run: |
          mkdir -p pacman_cache /root/.ccache
          pacman -Sy --noconfirm
          # circleci cache needs tar
          pacman -S tar --noconfirm
      - restore_cache:
          keys:
            - pacman-cache-{{ checksum "/tmp/date" }}
      - run: |
          pacman -Su --cachedir pacman_cache --noconfirm
          pacman -S --cachedir pacman_cache --noconfirm pkg-config git gcc meson itstool boost appstream-glib gettext gtk4 glib2 pipewire pipewire-pulse libsigc++-3.0 libsndfile libsamplerate zita-convolver libebur128 lilv lv2 calf zam-plugins rubberband mda.lv2 lsp-plugins rnnoise fftw libbs2b speexdsp nlohmann-json xorg-server-xvfb gawk ccache libadwaita tbb fmt gsl
          pacman -Sc --cachedir pacman_cache --noconfirm
      - save_cache:
          key: pacman-cache-{{ checksum "/tmp/date" }}
          paths:
            - pacman_cache
      - run: rm -rf pacman_cache
      # - run:
      #     name: Starting Xvfb
      #     command: Xvfb $DISPLAY -screen 0 1280x1024x24
      #     background: true
      # - run:
      #     name: Starting dbus
      #     command: |
      #       dbus-uuidgen > /var/lib/dbus/machine-id
      #       mkdir -p /var/run/dbus
      #       DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address) && echo $DBUS_SESSION_BUS_ADDRESS
      #       echo "export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" >> $BASH_ENV
      # - run:
      #     name: Starting PipeWire in background
      #     command: |
      #       sleep 5
      #       DISABLE_RTKIT=1 PIPEWIRE_DEBUG=4 pipewire
      #     background: true
      # - run:
      #     name: Starting pipewire-pulse in background
      #     command: |
      #       sleep 5
      #       DISABLE_RTKIT=1 pipewire-pulse
      #     background: true
      # - run:
      #     name: Starting pipewire-media-session in background
      #     command: |
      #       sleep 5
      #       DISABLE_RTKIT=1 pipewire-media-session
      #     background: true
      # - run:
      #     name: loading devices
      #     command: |
      #       sleep 5
      #       pactl load-module module-null-sink object.linger=1 media.class=Audio/Sink sink_name=my-sink audio.position=FL,FR
      #       pactl load-module module-null-sink object.linger=1 media.class=Audio/Source sink_name=my-source audio.position=FL,FR
      #       pw-cli list-objects Node
      #     background: true
      - restore_cache:
          keys:
            - ccache-{{ checksum "/tmp/date" }}
      - checkout
      - run:
          name: Compile and install EasyEffects
          command: |
            meson build && cd build && ninja -j 8 && ninja -j 8 install
      - save_cache:
          key: ccache-{{ checksum "/tmp/date" }}
          paths:
            - /root/.ccache
      # - run:
      #     name: Starting PE in background
      #     command: |
      #       easyeffects
      #     background: true
      # - run:
      #     name: Testing play/pause
      #     command: |
      #       .circleci/enable_all_plugins.sh
      #       # stream outputs
      #       #gst-launch-1.0 audiotestsrc num-buffers=100 ! queue ! pipewiresink
      #       #gst-launch-1.0 audiotestsrc num-buffers=100 ! queue ! pipewiresink
      #       # strem inputs
      #       #gst-launch-1.0 pipewiresrc num-buffers=100 ! queue ! audio/x-raw,format=F32LE ! pipewiresink
      #       #gst-launch-1.0 pipewiresrc num-buffers=100 ! queue ! audio/x-raw,format=F32LE ! pipewiresink
      # - run:
      #     name: Simulating audio applications
      #     command: |
      #       gst-launch-1.0 audiotestsrc ! queue ! pipewiresink &
      #       gst-launch-1.0 pipewiresrc ! queue ! audio/x-raw,format=F32LE ! pipewiresink
      #     background: true
      # - run:
      #     name: Testing plugin enable/disable on the fly
      #     command: |
      #       sleep 5
      #       .circleci/enable_all_plugins.sh
      #       sleep 1
      #       .circleci/disable_all_plugins.sh
      #       sleep 1
      #       .circleci/enable_all_plugins.sh
      # - run:
      #     name:         Testing presets
      #     command:      |
      #           sleep 5
      #           cp -v .circleci/presets/soe_preset_disable_all.json /root/.config/easyeffects/input
      #           cp -v .circleci/presets/soe_preset_enable_all.json /root/.config/easyeffects/input
      #           cp -v .circleci/presets/sie_preset_disable_all.json /root/.config/easyeffects/output
      #           cp -v .circleci/presets/sie_preset_enable_all.json /root/.config/easyeffects/output
      #           easyeffects -l soe_preset_disable_all || true
      #           sleep 1
      #           easyeffects -l soe_preset_enable_all || true
      #           sleep 1
      #           easyeffects -l sie_preset_disable_all || true
      #           sleep 1
      #           easyeffects -l sie_preset_enalbe_all || true
      # - run:
      #     name: Reset Configuration and finish
      #     command: |
      #       sleep 5
      #       easyeffects -r || true
      #       easyeffects -q || true

workflows:
  version: 2
  build:
    jobs:
      - archlinux
