dockapps/AlsaMixer.app/AMixer/AMixer.cc
Andreas Metzler 9881dba989 Clarify project copyright and license, use SPDX
Changes/additions in AlsaMixer.app over Mixer.app were lacking a
copyright information and and license specifications. Add the missing
bits, using a SPDX-License-Identifier.

Documentation for the change follows.
---------------------------------------------------

From petr.hlavka@avast.com Wed May  2 10:57:44 2018
Delivery-date: Wed, 02 May 2018 08:57:44 +0000
Received: from muffat.debian.org ([209.87.16.33])
	by vsrv21575.customer.vlinux.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.91)
	(envelope-from <petr.hlavka@avast.com>)
	id 1fDna2-0005LT-O4
	for ametzler@bebt.de; Wed, 02 May 2018 08:57:44 +0000
Received: from mail-qk0-x235.google.com ([2607:f8b0:400d:c09::235])
	by muffat.debian.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
	(Exim 4.89)
	(envelope-from <petr.hlavka@avast.com>)
	id 1fDna0-0001VT-VK
	for ametzler@bebt.de; Wed, 02 May 2018 08:57:41 +0000
Received: by mail-qk0-x235.google.com with SMTP id c70so10628010qkg.0
        for <ametzler@debian.org>; Wed, 02 May 2018 01:57:39 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=avast.com; s=google;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to;
        bh=todeyYOMQgF5NFi+g8Ch3ff7DLqVyjdpO1jnkiSCnwQ=;
        b=dTOhJ1+p5j29A0wiZExWtmDgNHdAYz4TBYldVuTScFHsdG2sEnQQJ0jhLcdJBZWtB/
         f9zbg70xN2O++EiXmWzHO///LWZQVvmqxRfWe9e9NinQiftLvebLt0qhNDqGurm0XGuR
         ElxIv7xaik7A76zuy4RiWLBQPJImsdbkj8w8o=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to;
        bh=todeyYOMQgF5NFi+g8Ch3ff7DLqVyjdpO1jnkiSCnwQ=;
        b=QruIZh5tAR6Ob3A5x4497372oBuHE3qBVI4pMDCb11By/sgVj7VWrzFcEzBKa+sZak
         J5y4nddBXL7usk4ULNYROXWym6dbjgcqqCX7nEdIQvze9FW7+bM/JMR+a69dxP2MFmVr
         v2P9F0xCyiU8MLXlvMQqgwmTPuyNAQgHledmWGWFzBjbKgJb7LDwM7Hs3aU7fTyRJm+1
         Ue4obJVABrLq398pXAlqupNDMb4F4Ss6/HcBxKhFKugxv5dRNCJFB0VPWl+/L/8qA6Dm
         1rUSVtcpoLdD1Tv+wZY9+rnzR4WVj/u/0JPhWIiH4UK4oeq0cLLEiUlVx3z5ZW4/xnlb
         cmmw==
X-Gm-Message-State: ALQs6tCW+VHY1vjrOxqi926/NtpVquOr/uyKzag66grdOQjv2d3QOHcx
	ITgzzFb/gW/K1WQYcwUDIpKXhav0rQUGhXagXfLCYjezYz8=
X-Google-Smtp-Source: AB8JxZrk2YDpWABvmBchDvRP6pMGHcJOS47obZEdkq/pZa72T3z10UOShV65Z5FzTjgF7CmqxSk2hmMpKTIzLbef3mA=
X-Received: by 10.55.120.68 with SMTP id t65mr15084912qkc.56.1525251456867;
 Wed, 02 May 2018 01:57:36 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.12.152.219 with HTTP; Wed, 2 May 2018 01:57:36 -0700 (PDT)
In-Reply-To: <20180430125042.GA1331@argenau.bebt.de>
References: <20180430125042.GA1331@argenau.bebt.de>
From: =?UTF-8?Q?Hl=C3=A1vka=2C_Petr?= <petr.hlavka@avast.com>
Date: Wed, 2 May 2018 10:57:36 +0200
Message-ID: <CACiAdzoA3hsfNG_5Xm-2wYJyZaEYH=xhK=8BrUq5YWVZRYncDg@mail.gmail.com>
Subject: Re: AlsaMixer.app - license?
To: Andreas Metzler <ametzler@debian.org>
Content-Type: multipart/alternative; boundary="94eb2c0a95da487efd056b354749"
Status: RO
X-Status: A
Content-Length: 3528

--94eb2c0a95da487efd056b354749
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello Andreas,

yes, I'm the author of modification to original Mixer.app (AlsaMixer.app).
They should be licensed under the same license as Mixer.app, some info is
available in
http://repo.or.cz/dockapps.git/blob_plain/HEAD:/AlsaMixer.app/README ,
section Copyright.

  Regards, Petr Hlavka.

On Mon, Apr 30, 2018 at 2:50 PM, Andreas Metzler <ametzler@debian.org>
wrote:

> Dear Mr Hl=C3=A1vka,
>
> I guess that you are the original author of AlsaMixer.app
> <https://www.dockapps.net/alsamixerapp>. If that is not case I am
> sorry for bothering you unnecessaly but would appreciate if you told
> me. - Thanks in advance
>
> On the other hand if you are the author it would be helpful if you could
> clarify the question of licensing. AlsaMixer.app is based on Mixer.app
> which is licensed under GNU General Public License version 2 or later.
> The modifications and additions for AlsaMixer.app only a carry a
> copyright info but no licensing info:
>
> Copyright
> --------------------------------------------------------------
> AlsaMixer.app, 2004, Petr Hlavka
> [...]
> // AChannel.cc, Petr Hlavka, 2004
>
> I guess that your contributions are also available under GPL v2 or
> later. Could you confirm this?
>
> Thanks in advance, kind Regards
>
> Andreas Metzler
>

--94eb2c0a95da487efd056b354749
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello Andreas,<div><br></div><div>yes, I&#39;m the author =
of modification to original Mixer.app (AlsaMixer.app). They should be licen=
sed under the same license as Mixer.app, some info is available in=C2=A0<a =
href=3D"http://repo.or.cz/dockapps.git/blob_plain/HEAD:/AlsaMixer.app/READM=
E">http://repo.or.cz/dockapps.git/blob_plain/HEAD:/AlsaMixer.app/README</a>=
 , section Copyright.</div><div><br></div><div>=C2=A0 Regards, Petr Hlavka.=
</div></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Mo=
n, Apr 30, 2018 at 2:50 PM, Andreas Metzler <span dir=3D"ltr">&lt;<a href=
=3D"mailto:ametzler@debian.org" target=3D"_blank">ametzler@debian.org</a>&g=
t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Mr Hl=C3=A1vka,<br>
<br>
I guess that you are the original author of AlsaMixer.app<br>
&lt;<a href=3D"https://www.dockapps.net/alsamixerapp" rel=3D"noreferrer" ta=
rget=3D"_blank">https://www.dockapps.net/<wbr>alsamixerapp</a>&gt;. If that=
 is not case I am <br>
sorry for bothering you unnecessaly but would appreciate if you told<br>
me. - Thanks in advance<br>
<br>
On the other hand if you are the author it would be helpful if you could<br=
>
clarify the question of licensing. AlsaMixer.app is based on Mixer.app<br>
which is licensed under GNU General Public License version 2 or later.<br>
The modifications and additions for AlsaMixer.app only a carry a<br>
copyright info but no licensing info:<br>
<br>
Copyright<br>
------------------------------<wbr>------------------------------<wbr>--<br=
>
AlsaMixer.app, 2004, Petr Hlavka<br>
[...]<br>
// AChannel.cc, Petr Hlavka, 2004<br>
<br>
I guess that your contributions are also available under GPL v2 or<br>
later. Could you confirm this?<br>
<br>
Thanks in advance, kind Regards<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br>
Andreas Metzler<br>
</font></span></blockquote></div><br></div>
2018-05-10 19:28:12 +01:00

208 lines
4.8 KiB
C++

// AMixer.cc
//
// Copyright (C) 2004, Petr Hlavka
//
// SPDX-License-Identifier: GPL-2.0+
#include "AMixer.h"
#include "AItem.h"
#include <alsa/asoundlib.h>
#include <iostream>
#include <cstdio>
#include <cstring>
static bool mixerChangeIndicator = false;
static bool mixerReinitIndicator = false;
static int mixerCallback(snd_mixer_t *ctl, unsigned int mask,
snd_mixer_elem_t *elem);
static int itemCallback(snd_mixer_elem_t *elem, unsigned int mask);
AMixer::AMixer(const char *card) {
int err;
if (card) {
cardName = new char[std::strlen(card)];
std::strcpy(cardName, card);
for (int i = 0; i < MIXER_ITEMS; i++)
mixerItems[i] = NULL;
if ((err = snd_mixer_open(&mixerHandle, 0)) < 0) {
error("snd_mixer_open error", err);
mixerHandle = NULL;
return;
}
if ((err = snd_mixer_attach(mixerHandle, card)) < 0) {
error("snd_mixer_attach error", err);
snd_mixer_close(mixerHandle);
mixerHandle = NULL;
return;
}
if ((err = snd_mixer_selem_register(mixerHandle, NULL, NULL)) < 0) {
error("snd_mixer_selem_register error", err);
snd_mixer_close(mixerHandle);
mixerHandle = NULL;
return;
}
if ((err = snd_mixer_load(mixerHandle)) < 0) {
error("snd_mixer_load error", err);
snd_mixer_close(mixerHandle);
mixerHandle = NULL;
return;
}
snd_mixer_set_callback(mixerHandle, (snd_mixer_callback_t) &mixerCallback);
}
}
AMixer::~AMixer() {
if (mixerHandle) {
snd_mixer_free(mixerHandle);
snd_mixer_detach(mixerHandle, cardName);
delete[] cardName;
snd_mixer_close(mixerHandle);
}
}
bool AMixer::opened() {
return (mixerHandle != NULL);
}
void AMixer::error(const char *errorString, int errorCode) {
std::cerr << cardName << ": " << errorString << ": " << snd_strerror(errorCode) << std::endl;
}
void AMixer::handleEvents() {
snd_mixer_handle_events(mixerHandle);
}
AItem *AMixer::attachItem(unsigned int itemNumber, const char *itemName) {
if (itemNumber >= MIXER_ITEMS || !itemName)
return (NULL);
// item was already created, so deregister callback and free it first
if (mixerItems[itemNumber]) {
snd_mixer_elem_set_callback(mixerItems[itemNumber]->aElem, NULL);
delete mixerItems[itemNumber];
}
// try to find item by name, register callback, return success
snd_mixer_elem_t *elem;
for (elem = snd_mixer_first_elem(mixerHandle); elem; elem = snd_mixer_elem_next(elem)) {
if (snd_mixer_selem_is_active(elem) &&
snd_mixer_elem_get_type(elem) == SND_MIXER_ELEM_SIMPLE &&
std::strcmp(snd_mixer_selem_get_name(elem), itemName) == 0) {
snd_mixer_elem_set_callback(elem, (snd_mixer_elem_callback_t) &itemCallback);
return (mixerItems[itemNumber] = new AItem(this, elem));
}
}
return (NULL);
}
bool AMixer::itemOK(unsigned int itemNumber) {
return (itemNumber < MIXER_ITEMS && mixerItems[itemNumber]);
}
int AMixer::itemGetVolume(unsigned int itemNumber) {
if (itemNumber >= MIXER_ITEMS || !mixerItems[itemNumber])
return (-1);
return ((int) mixerItems[itemNumber]->getVolumePerc());
}
void AMixer::itemSetVolume(unsigned int itemNumber, unsigned int volume) {
if (itemNumber < MIXER_ITEMS && mixerItems[itemNumber])
mixerItems[itemNumber]->setVolumePerc(volume);
}
int AMixer::itemIsMuted(unsigned int itemNumber) {
if (itemNumber >= MIXER_ITEMS || !mixerItems[itemNumber])
return (-1);
return ((bool) mixerItems[itemNumber]->isMuted());
}
void AMixer::itemToggleMute(unsigned int itemNumber) {
if (itemNumber < MIXER_ITEMS && mixerItems[itemNumber]) {
if (itemIsMuted(itemNumber))
mixerItems[itemNumber]->unmute();
else
mixerItems[itemNumber]->mute();
}
}
// return true if mixer elm sent callback and this callback wasn't picked up yet
bool AMixer::mixerElemsChanged() {
if (mixerChangeIndicator) {
mixerChangeIndicator = false;
return (true);
}
else
return (false);
}
// return true if mixer sent callback and this callback wasn't picked up yet
bool AMixer::mixerChanged() {
if (mixerReinitIndicator) {
mixerReinitIndicator = false;
return (true);
}
else
return (false);
}
// this function should be called after mixer callback, reInit all items
void AMixer::reInit() {
for (int i = 0; i < MIXER_ITEMS; i++)
this->attachItem(i, mixerItems[i]->name);
}
int mixerCallback(snd_mixer_t *ctl, unsigned int mask,
snd_mixer_elem_t *elem) {
mixerReinitIndicator = true;
return (0);
}
int itemCallback(snd_mixer_elem_t *elem, unsigned int mask) {
mixerChangeIndicator = true;
return (0);
}
char* AMixer::convertIDToCard(const char* cardId) {
static char card[32] = "";
int i = snd_card_get_index(cardId);
if (i >= 0 && i < 32)
std::snprintf(card, 32, "hw:%i", i);
else
return (NULL);
return (card);
}