-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
100 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,33 @@ | ||
{ compiler ? "ghc865", pkgs ? import <nixpkgs> {} }: | ||
|
||
let | ||
|
||
getvolume = pkgs.callPackage ./getvolume/default.nix { }; | ||
packageSet = pkgs.haskell.packages.${compiler}; | ||
haskellPackages = | ||
packageSet.override { | ||
overrides = (self: super: | ||
{ | ||
ghc = super.ghc // { withPackages = super.ghc.withHoogle; }; | ||
ghcWithPackages = self.ghc.withPackages; | ||
|
||
polysemy = self.polysemy_1_2_1_0; | ||
|
||
async-timer = pkgs.haskell.lib.dontCheck super.async-timer; | ||
|
||
polysemy-plugin = pkgs.haskell.lib.dontCheck (super.polysemy-plugin.override { polysemy = self.polysemy_1_2_1_0; }); | ||
} | ||
); | ||
}; | ||
drv = haskellPackages.callCabal2nix "barbq2" ./. {}; | ||
raw = haskellPackages.callCabal2nix "barbq" ./. {}; | ||
drv = pkgs.symlinkJoin { | ||
name = "barbq"; | ||
paths = [ raw getvolume ]; | ||
}; | ||
|
||
in | ||
{ | ||
barbq = drv; | ||
barbq-shell = haskellPackages.shellFor { | ||
packages = p: [drv]; | ||
packages = p: [raw]; | ||
shellHook = '' | ||
export HIE_HOOGLE_DATABASE="$(cat $(which hoogle) | sed -n -e 's|.*--database \(.*\.hoo\).*|\1|p')" | ||
pushd getvolume && swift build -c release && popd | ||
''; | ||
buildInputs = with pkgs; [ cabal-install hlint ghcid ] ++ (if pkgs.stdenv.isDarwin then [] else [ swift ]) ; | ||
buildInputs = with pkgs; [ cabal-install hlint ghcid getvolume ] ; | ||
}; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{pkgs ? import <nixpkgs> {} }: | ||
pkgs.stdenv.mkDerivation rec { | ||
name = "barbq-getvolume"; | ||
version = "0.2"; | ||
src = ./.; | ||
buildPhase = '' | ||
clang main.c -framework CoreAudio -framework AudioToolbox | ||
''; | ||
installPhase = '' | ||
mkdir -p $out/bin | ||
mv a.out $out/bin/barbq-getvolume | ||
''; | ||
buildInputs = [ pkgs.darwin.apple_sdk.frameworks.CoreAudio pkgs.darwin.apple_sdk.frameworks.AudioToolbox ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <AudioToolbox/AudioToolbox.h> | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
AudioDeviceID getCurrentlySelectedDeviceID() { | ||
UInt32 propertySize; | ||
AudioDeviceID deviceID = kAudioDeviceUnknown; | ||
|
||
AudioObjectPropertyAddress pa; | ||
pa.mScope = kAudioObjectPropertyScopeGlobal; | ||
pa.mElement = kAudioObjectPropertyElementMaster; | ||
pa.mSelector = kAudioHardwarePropertyDefaultOutputDevice; | ||
|
||
// get the default output device | ||
propertySize = sizeof(deviceID); | ||
|
||
OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &pa, 0, NULL, &propertySize, &deviceID); | ||
if (err != noErr) { | ||
fprintf(stderr, "Failed to get default deviceid\n"); | ||
} | ||
return deviceID; | ||
} | ||
|
||
UInt32 isMuted(AudioDeviceID deviceID) { | ||
UInt32 propertySize; | ||
|
||
AudioObjectPropertyAddress pa; | ||
pa.mSelector = kAudioDevicePropertyMute; | ||
pa.mScope = kAudioObjectPropertyScopeOutput; | ||
pa.mElement = kAudioObjectPropertyElementMaster; | ||
|
||
UInt32 isMuted = 0; | ||
propertySize = sizeof(isMuted); | ||
|
||
OSStatus err = AudioObjectGetPropertyData(deviceID, &pa, 0, NULL, &propertySize, &isMuted); | ||
if (err != noErr) { | ||
fprintf(stderr, "Failed to get mute data\n"); | ||
} | ||
|
||
return isMuted; | ||
} | ||
|
||
void getDeviceVolume(AudioDeviceID deviceID, float *volume) { | ||
UInt32 propertySize = sizeof(float); | ||
|
||
AudioObjectPropertyAddress pa; | ||
pa.mSelector = kAudioHardwareServiceDeviceProperty_VirtualMasterVolume; | ||
pa.mScope = kAudioDevicePropertyScopeOutput; | ||
pa.mElement = kAudioObjectPropertyElementMaster; | ||
|
||
OSStatus err = AudioObjectGetPropertyData( | ||
deviceID, | ||
&pa, | ||
0, | ||
NULL, | ||
&propertySize, | ||
volume); | ||
if (err != noErr) { | ||
fprintf(stderr, "Failed to get volume data\n"); | ||
return; | ||
} | ||
} | ||
|
||
int main() { | ||
AudioDeviceID deviceID = getCurrentlySelectedDeviceID(); | ||
UInt32 mute = isMuted(deviceID); | ||
float volume = 100.0; | ||
getDeviceVolume(deviceID, &volume); | ||
printf("%d,%d\n", (int)round(volume*100.0), mute); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
cradle: | ||
cabal: | ||
component: "exe:barbq2" | ||
component: "exe:barbq" | ||
|
||
dependencies: | ||
- barbq2.cabal | ||
- barbq.cabal | ||
- shell.nix | ||
- default.nix |