Exemplo n.º 1
0
void MidiPort::setMidiDevice(MidiDevice* dev)
{
    // close old device
    if (_device)
    {
        _device->setPort(-1);
        _device->close();
    }
    // set-up new device
    if (dev)
    {
        for (int i = 0; i < kMaxMidiPorts; ++i)
        {
            MidiPort* mp = &midiPorts[i];
            if (mp->device() == dev)
            {
                // move device
                _state = mp->state();
                mp->clearDevice();
                break;
            }
        }
        _device = dev;
        _state = _device->open();
        _device->setPort(portno());
    }
    else
        // dev is null, clear this device
        clearDevice();
}
Exemplo n.º 2
0
void MidiPort::tryCtrlInitVal(int chan, int ctl, int val)
{
	//printf("Entering: MidiPort::tryCtrlInitVal\n");
	if (_instrument)
	{
		MidiControllerList* cl = _instrument->controller();
		ciMidiController imc = cl->find(ctl);
		if (imc != cl->end())
		{
			MidiController* mc = imc->second;
			int initval = mc->initVal();

			// Initialize from either the instrument controller's initial value, or the supplied value.
			if (initval != CTRL_VAL_UNKNOWN)
			{
				if (_device)
				{
					MidiPlayEvent ev(0, portno(), chan, ME_CONTROLLER, ctl, initval + mc->bias());
					_device->putEvent(ev);
				}
				setHwCtrlStates(chan, ctl, CTRL_VAL_UNKNOWN, initval + mc->bias());

				return;
			}
		}
	}

	if (_device)
	{
		//MidiPlayEvent ev(song->cpos(), portno(), chan, ME_CONTROLLER, ctl, val);
		MidiPlayEvent ev(0, portno(), chan, ME_CONTROLLER, ctl, val);
		_device->putEvent(ev);
	}
	// Set it once so the 'last HW value' is set, and control knobs are positioned at the value...
	//setHwCtrlState(chan, ctl, val);
	// Set it again so that control labels show 'off'...
	//setHwCtrlState(chan, ctl, CTRL_VAL_UNKNOWN);
	setHwCtrlStates(chan, ctl, CTRL_VAL_UNKNOWN, val);
}
Exemplo n.º 3
0
/*
 *  set a local address and port from a string of the form
 *	[address!]port[!r]
 */
static void
setladdrport(Conv *c, char *str, int announcing)
{
	char *p;
	int lport;

	/*
	 *  ignore restricted part if it exists.  it's
	 *  meaningless on local ports.
	 */
	p = strchr(str, '!');
	if(p != nil){
		*p++ = 0;
		if(strcmp(p, "r") == 0)
			p = nil;
	}

	c->lport = 0;
	if(p == nil){
		if(announcing)
			ipmove(c->laddr, IPnoaddr);
		else if(0)
			setladdr(c);
		p = str;
	} else {
		if(strcmp(str, "*") == 0)
			ipmove(c->laddr, IPnoaddr);
		else if(parseip(c->laddr, str) == 0)
			error("invalid IP address");
	}

	if(announcing && strcmp(p, "*") == 0){
		if(!iseve())
			error(Eperm);
		c->lport = 0;
		setlport(c);
		return;
	}

	lport = portno(p);
	if(lport <= 0)
		c->lport = 0;
	else
		c->lport = lport;

	setlport(c);
}
Exemplo n.º 4
0
static char*
setraddrport(Conv *c, char *str)
{
	char *p;

	p = strchr(str, '!');
	if(p == nil)
		return "malformed address";
	*p++ = 0;
	if(parseip(c->raddr, str) == 0)
		return "invalid IP address";
	c->rport = portno(p);
	p = strchr(p, '!');
	if(p){
		if(strstr(p, "!r") != nil)
			c->restricted = 1;
	}
	return nil;
}
Exemplo n.º 5
0
void MidiPort::setMidiDevice(MidiDevice* dev)
{
    // close old device
	if (_device)
	{
        if (_device->isSynthPlugin())
		{
			_instrument = genericMidiInstrument;
		}
		_device->setPort(-1);
		_device->close();
	}
    // set-up new device
	if (dev)
	{
		for (int i = 0; i < MIDI_PORTS; ++i)
		{
			MidiPort* mp = &midiPorts[i];
			if (mp->device() == dev)
			{
                if (dev->isSynthPlugin())
					mp->setInstrument(genericMidiInstrument);
				// move device
				_state = mp->state();
				mp->clearDevice();
				break;
			}
		}
		_device = dev;
        if (_device->isSynthPlugin())
		{
            SynthPluginDevice* s = (SynthPluginDevice*) _device;
			_instrument = s;
            //_instrument = genericMidiInstrument;
		}
		_state = _device->open();
		_device->setPort(portno());
	}
	else
        // dev is null, clear this device
		clearDevice();
}
Exemplo n.º 6
0
static void
connectctlmsg(Proto *x, Conv *c, Cmdbuf *cb)
{
	char *p;

	USED(x);
	if(c->state != Idle)
		error(Econinuse);
	c->state = Connecting;
	c->cerr[0] = '\0';
	switch(cb->nf) {
	default:
		error("bad args to connect");
	case 2:
		p = setraddrport(c, cb->f[1]);
		if(p != nil)
			error(p);
		break;
	case 3:
		p = setraddrport(c, cb->f[1]);
		if(p != nil)
			error(p);
		c->lport = portno(cb->f[2]);
		setlport(c);
		break;
	}
	qunlock(&c->l);
	if(waserror()){
		qlock(&c->l);
		c->state = Connected;	/* sic */
		nexterror();
	}
	/* p = x->connect(c, cb->f, cb->nf); */
	so_connect(c->sfd, c->raddr, c->rport);
	qlock(&c->l);
	poperror();
	setladdr(c);
	c->state = Connected;
}