Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

midi API needs support for ProgramChange, ChannelPressure and PolyPressure events #46

Open
steveschow opened this issue Nov 19, 2021 · 1 comment

Comments

@steveschow
Copy link

Current API module does not have any support for getting or setting ProgramChange, ChannelPressure and PolyPressure midi events. Why not?

@pho70n
Copy link

pho70n commented Jan 22, 2023

Don't know why, but it's very easy to add those events in:

	pos = pos or 0
	local n = midi.Event(pos, 3)
	n.data[0] = bor(0xd0, channel-1)
	n.data[1] = band(val, 127)
	n.data[2] = 0x00
	return n
end

midi.Event.polyPressure = function (channel, val, noteId, pos)
	pos = pos or 0
	local n = midi.Event(pos, 3)
	n.data[0] = bor(0xa0, channel-1)
	n.data[1] = band(noteId, 127)
	n.data[2] = band(val, 127)
	return n
end

And under MidiEvent_mt

		--- Is a channel aftertouch event.
		-- @treturn boolean whether event is a channel aftertouch event.
		-- @function Event:isControl
		isPressure = function (self)
			return band(self.data[0], 0xf0)==0xd0
		end;

		
		--- Get aftertouch value.
		-- @return pressure value (0-127).
		-- @function Event:getPressureValue
		getPressureValue = function (self)
			if not self:isPressure() then error "not a channel pressure event" end
			return self.data[2]
		end;

		--- Is a polyphonic pressure event.
		-- @treturn boolean whether event is a polyphonic pressure event.
		-- @function Event:isControl
		isPolyPressure = function (self)
			return band(self.data[0], 0xf0)==0xa0
		end;

		--- Get pressure note ID value.
		-- @return note ID (0-127).
		-- @function Event:getPolyPressureValue
		getPolyPressureNoteID = function (self)
			if not self:isPolyPressure() then error "not a polyphonic pressure event" end
			return self.data[1]
		end;

		--- Get poly pressure value.
		-- @return pressure value (0-127).
		-- @function Event:getPolyPressureValue
		getPolyPressureValue = function (self)
			if not self:isPolyPressure() then error "not a channel pressure event" end
			return self.data[2]
		end;

I hadn't implemented program change but it's pretty simple. Replace the modified midi.lua in the protoplugs folder and you're golden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants