Beispiel #1
0
/*
 * Class:     org_tritonus_lowlevel_alsa_AlsaMixerElement
 * Method:    isCaptureMono
 * Signature: ()Z
 */
JNIEXPORT jboolean JNICALL
Java_org_tritonus_lowlevel_alsa_AlsaMixerElement_isCaptureMono
(JNIEnv* env, jobject obj)
{
    snd_mixer_elem_t*	handle;
    int			nReturn;

    if (debug_flag) {
        (void) fprintf(debug_file, "Java_org_tritonus_lowlevel_alsa_AlsaMixerElement_isCaptureMono(): begin\n");
    }
    handle = getHandle(env, obj);
    nReturn = snd_mixer_selem_is_capture_mono(handle);
    if (debug_flag) {
        (void) fprintf(debug_file, "Java_org_tritonus_lowlevel_alsa_AlsaMixerElement_isCaptureMono(): end\n");
    }
    return (jboolean) nReturn;
}
Beispiel #2
0
MixerElem *lamixer_volelem_new(snd_mixer_elem_t *elem)
{
	MixerElem *mixer_elem;
	guint voltype=0, elemidx=0, mono;
	long minrange=0,maxrange=0,rangevalue_left=0,rangevalue_right=0;
	const char* selem_name = NULL;
	char elem_name[64];
	
	mixer_elem = g_malloc(sizeof(MixerElem));
	mixer_elem->elem = elem;
	mixer_elem->playback = NULL;
	mixer_elem->capture = NULL;
	mixer_elem->pswitch = NULL;
	mixer_elem->cswitch = NULL;
	mixer_elem->penum = NULL;
	mixer_elem->cenum = NULL;
	
	elemidx = snd_mixer_selem_get_index(elem);
	selem_name = snd_mixer_selem_id_get_name(sid);
	strcpy(elem_name, selem_name);
	if(elemidx > 0) {
		sprintf(elem_name,"%s %i",elem_name, elemidx);
	}
	
	if (!snd_mixer_selem_is_enumerated(elem)) {
		if (snd_mixer_selem_has_playback_volume(elem)) {
			voltype = 1;
			snd_mixer_selem_get_playback_volume_range (elem, &minrange, &maxrange);
			mono = snd_mixer_selem_is_playback_mono(elem);
			snd_mixer_selem_get_playback_volume (elem, SND_MIXER_SCHN_FRONT_LEFT, &rangevalue_left);
			
			if(!mono)
				snd_mixer_selem_get_playback_volume (elem, SND_MIXER_SCHN_FRONT_RIGHT, &rangevalue_right);
			
			mixer_elem->playback = lamixer_volbox_new(elem_name,mono, \
			                                                (snd_mixer_selem_has_playback_switch(elem) || snd_mixer_selem_has_playback_switch_joined(elem)), minrange, maxrange, elem, voltype);
		}
		else if (snd_mixer_selem_has_playback_switch(elem)) {
			voltype = 1;
			mixer_elem->pswitch = lamixer_switchbox_add(elem_name, elem, voltype);
		}
		
		if (snd_mixer_selem_has_capture_volume(elem)) {
			voltype = 2;
			snd_mixer_selem_get_capture_volume_range (elem, &minrange, &maxrange);
			mono = snd_mixer_selem_is_capture_mono(elem);
			snd_mixer_selem_get_capture_volume (elem, SND_MIXER_SCHN_FRONT_LEFT, &rangevalue_left);
			
			if(!mono)
				snd_mixer_selem_get_capture_volume (elem, SND_MIXER_SCHN_FRONT_RIGHT, &rangevalue_right);
			
			mixer_elem->capture = lamixer_volbox_new(elem_name,mono, \
									(snd_mixer_selem_has_capture_switch(elem) || snd_mixer_selem_has_capture_switch_joined(elem)), minrange, maxrange, elem, voltype);
		}
		else if (snd_mixer_selem_has_capture_switch(elem)) {
			voltype = 2;
			mixer_elem->cswitch = lamixer_switchbox_add(elem_name, elem, voltype);
		}
	}
	else {
		if (snd_mixer_selem_is_enum_playback(elem)) {
			voltype = 1;
			mixer_elem->penum = lamixer_enumbox_add(elem_name, elem, voltype);
		}
		else if (snd_mixer_selem_is_enum_capture(elem)) {
			voltype = 2;
			mixer_elem->cenum = lamixer_enumbox_add(elem_name, elem, voltype);
		}
	}
		
	return mixer_elem;
}
void PORT_GetControls(void* id, INT32 portIndex, PortControlCreator* creator) {
    PortMixer* portMixer;
    snd_mixer_elem_t* elem;
    void* control;
    PortControl* portControl;
    void* controls[10];
    int numControls;
    char* portName;
    int isPlayback = 0;
    int isMono;
    int isStereo;
    char* type;
    snd_mixer_selem_channel_id_t channel;

    TRACE0("> PORT_GetControls\n");
    if (id == NULL) {
        ERROR0("Invalid handle!");
        // $$mp: an error code should be returned.
        return;
    }
    portMixer = (PortMixer*) id;
    if (portIndex < 0 || portIndex >= portMixer->numElems) {
        ERROR0("Port index out of range!");
        // $$mp: an error code should be returned.
        return;
    }
    numControls = 0;
    elem = portMixer->elems[portIndex];
    if (snd_mixer_selem_has_playback_volume(elem) || snd_mixer_selem_has_capture_volume(elem)) {
        /* Since we've split/duplicated elements with both playback and capture on the recovery
           of elements, we now can assume that we handle only to deal with either playback or
           capture. */
        isPlayback = isPlaybackFunction(portMixer->types[portIndex]);
        isMono = (isPlayback && snd_mixer_selem_is_playback_mono(elem)) ||
            (!isPlayback && snd_mixer_selem_is_capture_mono(elem));
        isStereo = (isPlayback &&
                    snd_mixer_selem_has_playback_channel(elem, SND_MIXER_SCHN_FRONT_LEFT) &&
                    snd_mixer_selem_has_playback_channel(elem, SND_MIXER_SCHN_FRONT_RIGHT)) ||
            (!isPlayback &&
             snd_mixer_selem_has_capture_channel(elem, SND_MIXER_SCHN_FRONT_LEFT) &&
             snd_mixer_selem_has_capture_channel(elem, SND_MIXER_SCHN_FRONT_RIGHT));
        // single volume control
        if (isMono || isStereo) {
            if (getControlSlot(portMixer, &portControl)) {
                portControl->elem = elem;
                portControl->portType = portMixer->types[portIndex];
                portControl->controlType = CONTROL_TYPE_VOLUME;
                if (isMono) {
                    portControl->channel = CHANNELS_MONO;
                } else {
                    portControl->channel = CHANNELS_STEREO;
                }
                control = createVolumeControl(creator, portControl, elem, isPlayback);
                if (control != NULL) {
                    controls[numControls++] = control;
                }
            }
        } else { // more than two channels, each channels has its own control.
            for (channel = SND_MIXER_SCHN_FRONT_LEFT; channel <= SND_MIXER_SCHN_LAST; channel++) {
                if ((isPlayback && snd_mixer_selem_has_playback_channel(elem, channel)) ||
                    (!isPlayback && snd_mixer_selem_has_capture_channel(elem, channel))) {
                    if (getControlSlot(portMixer, &portControl)) {
                        portControl->elem = elem;
                        portControl->portType = portMixer->types[portIndex];
                        portControl->controlType = CONTROL_TYPE_VOLUME;
                        portControl->channel = channel;
                        control = createVolumeControl(creator, portControl, elem, isPlayback);
                        // We wrap in a compound control to provide the channel name.
                        if (control != NULL) {
                            /* $$mp 2003-09-14: The following cast shouln't be necessary. Instead, the
                               declaration of PORT_NewCompoundControlPtr in Ports.h should be changed
                               to take a const char* parameter. */
                            control = (creator->newCompoundControl)(creator, (char*) snd_mixer_selem_channel_name(channel), &control, 1);
                        }
                        if (control != NULL) {
                            controls[numControls++] = control;
                        }
                    }
                }
            }
        }
        // BALANCE control
        if (isStereo) {
            if (getControlSlot(portMixer, &portControl)) {
                portControl->elem = elem;
                portControl->portType = portMixer->types[portIndex];
                portControl->controlType = CONTROL_TYPE_BALANCE;
                portControl->channel = CHANNELS_STEREO;
                /* $$mp: The value for precision is chosen more or less arbitrarily. */
                control = (creator->newFloatControl)(creator, portControl, CONTROL_TYPE_BALANCE, -1.0F, 1.0F, 0.01F, "");
                if (control != NULL) {
                    controls[numControls++] = control;
                }
            }
        }
    }
    if (snd_mixer_selem_has_playback_switch(elem) || snd_mixer_selem_has_capture_switch(elem)) {
        if (getControlSlot(portMixer, &portControl)) {
            type = isPlayback ? CONTROL_TYPE_MUTE : CONTROL_TYPE_SELECT;
            portControl->elem = elem;
            portControl->portType = portMixer->types[portIndex];
            portControl->controlType = type;
            control = (creator->newBooleanControl)(creator, portControl, type);
            if (control != NULL) {
                controls[numControls++] = control;
            }
        }
    }
    /* $$mp 2003-09-14: The following cast shouln't be necessary. Instead, the
       declaration of PORT_NewCompoundControlPtr in Ports.h should be changed
       to take a const char* parameter. */
    portName = (char*) snd_mixer_selem_get_name(elem);
    control = (creator->newCompoundControl)(creator, portName, controls, numControls);
    if (control != NULL) {
        (creator->addControl)(creator, control);
    }
    TRACE0("< PORT_GetControls\n");
}