<commit_before>-module(volume).
-behaviour(gen_server).

-export([start/1]).
-export([get/0, set/1]).
-export([init/1, handle_call/3]).

%---------------------------------------------------------------------------

start(Sconf) ->
    io:format("Starting volume control.~n"),
    gen_server:start_link({local, volume}, volume, [], []).

%---------------------------------------------------------------------------

get() -> gen_server:call(volume, get).
set(NewVol) -> gen_server:call(volume, {set, NewVol}).

%---------------------------------------------------------------------------

init(_Args) ->
    {ok, unknown}.

handle_call(Request, From, unknown) ->
    handle_call(Request, From, hmix_get_volume());
handle_call(get, _From, Volume) ->
    {reply, Volume, Volume};
handle_call({set, VolArg}, _From, _Volume) ->
    NewVol = hmix_set_volume(VolArg),
    {reply, NewVol, unknown}.

hmix_get_volume() ->
    Out = os:cmd("hmix | grep MASTER"),
    case lists:prefix("MASTER", Out) of
	true ->
	    {match, Start, Length} = regexp:match(Out, "[0-9]+"),
	    VolStr = string:substr(Out, Start, Length),
	    list_to_integer(VolStr);
	false ->
	    unavailable
    end.

hmix_set_volume(NewVol) ->
    os:cmd("hmix -master " ++ integer_to_list(NewVol)),
    hmix_get_volume().
<commit_msg>Use "null" instead of "unavailable" for hmix<commit_after>-module(volume).
-behaviour(gen_server).

-export([start/1]).
-export([get/0, set/1]).
-export([init/1, handle_call/3]).

%---------------------------------------------------------------------------

start(Sconf) ->
    io:format("Starting volume control.~n"),
    gen_server:start_link({local, volume}, volume, [], []).

%---------------------------------------------------------------------------

get() -> gen_server:call(volume, get).
set(NewVol) -> gen_server:call(volume, {set, NewVol}).

%---------------------------------------------------------------------------

init(_Args) ->
    {ok, unknown}.

handle_call(Request, From, unknown) ->
    handle_call(Request, From, hmix_get_volume());
handle_call(get, _From, Volume) ->
    {reply, Volume, Volume};
handle_call({set, VolArg}, _From, _Volume) ->
    NewVol = hmix_set_volume(VolArg),
    {reply, NewVol, unknown}.

hmix_get_volume() ->
    Out = os:cmd("hmix | grep MASTER"),
    case lists:prefix("MASTER", Out) of
	true ->
	    {match, Start, Length} = regexp:match(Out, "[0-9]+"),
	    VolStr = string:substr(Out, Start, Length),
	    list_to_integer(VolStr);
	false ->
	    null
    end.

hmix_set_volume(NewVol) ->
    os:cmd("hmix -master " ++ integer_to_list(NewVol)),
    hmix_get_volume().

{'fraction_non_alphanumeric': 0.32899770466717676, 'fraction_numerical': 0.005355776587605203, 'mean_word_length': 1.9682179341657207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5641078', 'n_tokens_mistral': 824, 'n_tokens_neox': 803, 'n_words': 152}