doudbassctrlr

Forum Replies Created

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • in reply to: Reading Musicxml files #24676
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    I have some troubles understanding how works Lua. XmlDocument is a C++ class implemented in Juce. I have some basics of C++ but I do not know how to use its constructor in Lua.
    What follows:

    -- @file      a File object that represents the double clicked file
    [...]
    myfile=XmlDocument(file)
    [...]

    gives me a runtime error message: “attempt to call global ‘XmlDocument’ (a nil value)”

    However file really seems to be a File object as required…

    in reply to: Reading Musicxml files #24659
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    Great I didn’t know about Juce and its xml functions. Moreover it looks quite flexible and it should allow me to read the Musicxml files.

    Just to start with, can someone help me to understand how to use Juce functions in Lua methods?

    in reply to: Reading Musicxml files #24653
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    Hello,
    I am having a first try with a code named Slaxml.lua that is given below. I have integrated it to a method called when file is double clicked in the uiFileListBox options and get a lua runtime error saying “at line [-1]: [C] Error message: No such operator defined”.
    Any idea of what is going on?

    --[=====================================================================[
    --v0.6 Copyright © 2013-2014 Gavin Kistner <!@phrogz.net>; MIT Licensed
    --See http://github.com/Phrogz/SLAXML for details.
    --]=====================================================================]
    local SLAXML = {
    	VERSION = "0.6",
    	_call = {
    		pi = function(target,content)
    			print(string.format("<?%s %s?>",target,content))
    		end,
    		comment = function(content)
    			print(string.format("<!-- %s -->",content))
    		end,
    		startElement = function(name,nsURI,nsPrefix)
    			                 io.write("<")
    			if nsPrefix then io.write(nsPrefix,":") end
    			                 io.write(name)
    			if nsURI    then io.write(" (ns='",nsURI,"')") end
    			                 print(">")
    		end,
    		attribute = function(name,value,nsURI,nsPrefix)
    			io.write('  ')
    			if nsPrefix then io.write(nsPrefix,":") end
    			                 io.write(name,'=',string.format('%q',value))
    			if nsURI    then io.write(" (ns='",nsURI,"')") end
    			io.write("\n")
    		end,
    		text = function(text)
    			print(string.format("  text: %q",text))
    		end,
    		closeElement = function(name,nsURI,nsPrefix)
    			print(string.format("</%s>",name))
    		end,
    	}
    }
    
    function SLAXML:parser(callbacks)
    	return { _call=callbacks or self._call, parse=SLAXML.parse }
    end
    
    function SLAXML:parse(xml,options)
    	if not options then options = { stripWhitespace=false } end
    
    	-- Cache references for maximum speed
    	local find, sub, gsub, char, push, pop = string.find, string.sub, string.gsub, string.char, table.insert, table.remove
    	local first, last, match1, match2, match3, pos2, nsURI
    	local unpack = unpack or table.unpack
    	local pos = 1
    	local state = "text"
    	local textStart = 1
    	local currentElement={}
    	local currentAttributes={}
    	local currentAttributeCt -- manually track length since the table is re-used
    	local nsStack = {}
    
    	local entityMap  = { ["lt"]="<", ["gt"]=">", ["amp"]="&", ["quot"]='"', ["apos"]="'" }
    	local entitySwap = function(orig,n,s) return entityMap or n=="#" and char(s) or orig end
    	local function unescape(str) return gsub( str, '(&(#?)([%d%a]+);)', entitySwap ) end
    	local anyElement = false
    
    	local function finishText()
    		if first>textStart and self._call.text then
    			local text = sub(xml,textStart,first-1)
    			if options.stripWhitespace then
    				text = gsub(text,'^%s+','')
    				text = gsub(text,'%s+$','')
    				if #text==0 then text=nil end
    			end
    			if text then self._call.text(unescape(text)) end
    		end
    	end
    
    	local function findPI()
    		first, last, match1, match2 = find( xml, '^<%?([:%a_][:%w_.-]*) ?(.-)%?>', pos )
    		if first then
    			finishText()
    			if self._call.pi then self._call.pi(match1,match2) end
    			pos = last+1
    			textStart = pos
    			return true
    		end
    	end
    
    	local function findComment()
    		first, last, match1 = find( xml, '^<!%-%-(.-)%-%->', pos )
    		if first then
    			finishText()
    			if self._call.comment then self._call.comment(match1) end
    			pos = last+1
    			textStart = pos
    			return true
    		end
    	end
    
    	local function nsForPrefix(prefix)
    		if prefix=='xml' then return 'http://www.w3.org/XML/1998/namespace' end -- http://www.w3.org/TR/xml-names/#ns-decl
    		for i=#nsStack,1,-1 do if nsStack[prefix] then return nsStack[prefix] end end
    		error(("Cannot find namespace for prefix %s"):format(prefix))
    	end
    
    	local function startElement()
    		anyElement = true
    		first, last, match1 = find( xml, '^<([%a_][%w_.-]*)', pos )
    		if first then
    			currentElement[2] = nil -- reset the nsURI, since this table is re-used
    			currentElement[3] = nil -- reset the nsPrefix, since this table is re-used
    			finishText()
    			pos = last+1
    			first,last,match2 = find(xml, '^:([%a_][%w_.-]*)', pos )
    			if first then
    				currentElement[1] = match2
    				currentElement[3] = match1 -- Save the prefix for later resolution
    				match1 = match2
    				pos = last+1
    			else
    				currentElement[1] = match1
    				for i=#nsStack,1,-1 do if nsStack['!'] then currentElement[2] = nsStack['!']; break end end
    			end
    			currentAttributeCt = 0
    			push(nsStack,{})
    			return true
    		end
    	end
    
    	local function findAttribute()
    		first, last, match1 = find( xml, '^%s+([:%a_][:%w_.-]*)%s*=%s*', pos )
    		if first then
    			pos2 = last+1
    			first, last, match2 = find( xml, '^"([^<"]*)"', pos2 ) -- FIXME: disallow non-entity ampersands
    			if first then
    				pos = last+1
    				match2 = unescape(match2)
    			else
    				first, last, match2 = find( xml, "^'([^<']*)'", pos2 ) -- FIXME: disallow non-entity ampersands
    				if first then
    					pos = last+1
    					match2 = unescape(match2)
    				end
    			end
    		end
    		if match1 and match2 then
    			local currentAttribute = {match1,match2}
    			local prefix,name = string.match(match1,'^([^:]+):([^:]+)$')
    			if prefix then
    				if prefix=='xmlns' then
    					nsStack[#nsStack][name] = match2
    				else
    					currentAttribute[1] = name
    					currentAttribute[4] = prefix
    				end
    			else
    				if match1=='xmlns' then
    					nsStack[#nsStack]['!'] = match2
    					currentElement[2]      = match2
    				end
    			end
    			currentAttributeCt = currentAttributeCt + 1
    			currentAttributes[currentAttributeCt] = currentAttribute
    			return true
    		end
    	end
    
    	local function findCDATA()
    		first, last, match1 = find( xml, '^<!%[CDATA%[(.-)%]%]>', pos )
    		if first then
    			finishText()
    			if self._call.text then self._call.text(match1) end
    			pos = last+1
    			textStart = pos
    			return true
    		end
    	end
    
    	local function closeElement()
    		first, last, match1 = find( xml, '^%s*(/?)>', pos )
    		if first then
    			state = "text"
    			pos = last+1
    			textStart = pos
    
    			-- Resolve namespace prefixes AFTER all new/redefined prefixes have been parsed
    			if currentElement[3] then currentElement[2] = nsForPrefix(currentElement[3])    end
    			if self._call.startElement then self._call.startElement(unpack(currentElement)) end
    			if self._call.attribute then
    				for i=1,currentAttributeCt do
    					if currentAttributes[4] then currentAttributes[3] = nsForPrefix(currentAttributes[4]) end
    					self._call.attribute(unpack(currentAttributes))
    				end
    			end
    
    			if match1=="/" then
    				pop(nsStack)
    				if self._call.closeElement then self._call.closeElement(unpack(currentElement)) end
    			end
    			return true
    		end
    	end
    
    	local function findElementClose()
    		first, last, match1, match2 = find( xml, '^</([%a_][%w_.-]*)%s*>', pos )
    		if first then
    			nsURI = nil
    			for i=#nsStack,1,-1 do if nsStack['!'] then nsURI = nsStack['!']; break end end
    		else
    			first, last, match2, match1 = find( xml, '^</([%a_][%w_.-]*):([%a_][%w_.-]*)%s*>', pos )
    			if first then nsURI = nsForPrefix(match2) end
    		end
    		if first then
    			finishText()
    			if self._call.closeElement then self._call.closeElement(match1,nsURI) end
    			pos = last+1
    			textStart = pos
    			pop(nsStack)
    			return true
    		end
    	end
    
    	while pos<#xml do
    		if state=="text" then
    			if not (findPI() or findComment() or findCDATA() or findElementClose()) then		
    				if startElement() then
    					state = "attributes"
    				else
    					first, last = find( xml, '^[^<]+', pos )
    					pos = (first and last or pos) + 1
    				end
    			end
    		elseif state=="attributes" then
    			if not findAttribute() then
    				if not closeElement() then
    					error("Was in an element and couldn't find attributes or the close.")
    				end
    			end
    		end
    	end
    
    	if not anyElement then error("Parsing did not discover any elements") end
    	if #nsStack > 0 then error("Parsing ended with unclosed elements") end
    end
    
    --return SLAXML
    --
    -- Called when a file is double clicked
    --
    -- @modulator the modulator the event occured on
    -- @file      a File object that represents the double clicked file
    --
    MusixmlReader = function(modulator, file)
    SLAXML:parse(file)
    end
    in reply to: Sending Midi Notes to a bidule rack #24010
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    I agree that MidiThru do not concern midi messages delivered by the panel but it was the options you previously adviced me to check…
    The “output to plugin host” however should do the job as far as I understand it and it does when Lua script is not involved, that is when I want to use the Midi messages pre-build options in the uibutton side panel.
    Now I thought that sendMidiMessageNow(..) from Lua would deliver midi messages the same way (i.e. to the plugin output) and was not linked to any output device port…

    in reply to: Sending Midi Notes to a bidule rack #23997
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    Thanks a lot for your help. I now get the programmed midi notes. I am getting closer now to a solution, however I am getting confused about some routing points. More specificaly: it seems that sendMidiMessageNow() can only send midi to a Midi output device while Midi options of the uicomponent can lead to the plugin output… Am I wrong?

    Now, here is how it works for me:
    – To get Lua method programmed midi messages working I had to select an output device and I had none, so I used a virtual midi cable
    – The plugin output won’t deliver Midi messages from the Lua Method and I can uncheck all the MidiThru options and output to plugin. And it still works as far as the output virtual cable is correctly plugged in.

    So strange… I do not understand this routing issue…
    Any idea?

    in reply to: Sending Midi Notes to a bidule rack #23980
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    I have tried the lua code with a new slider in a new panel using the indicated options but nothing new.
    What I am now sure of is that the Lua code is well read since a console test can well be printed when modulator value is changed. However what I cannot figure out is why sendMidiMessageNow(…) function do not produce any output.
    Is there another function that would lead to a midi message output?

    in reply to: Sending Midi Notes to a bidule rack #23787
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    Finaly one reassuring point. I am not going completly wrong with the lua code and it should lead to delivering midi messages.
    – Which version of Ctrlr are you using?
    – Is it working with the vst version?

    I tried to use another DAW as plugin host (Reaper) and build a new vst with all the indicated options for delivering midi messages checked. I inserted only one uibutton and attributed the Lua method to be sent when modulator value is changed. It does not work either…
    Any new idea?

    in reply to: Sending Midi Notes to a bidule rack #23681
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    I have just tried this combinaison of options but nothing new.
    It seems to me that “Output to plugin host” should be sufficient as, for the moment, I am just trying to send Midi messages through the Lua method as I toggle the uibutton…

    in reply to: Sending Midi Notes to a bidule rack #23673
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    I have never used Lua before but I am a bit familiar with C++.
    I think I will be able to go further in the vst construction if I can fix the midi sending problems.
    Do anybody know what is going wrong with the Lua method given in the above replies?
    Do you have any simple test for me to check if sending midi message through Lua is working correctly?
    Thanks a lot

    in reply to: Sending Midi Notes to a bidule rack #23445
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    It seems that everything is correctly plugged in, I am able to switch on/off the “moot” vst. Ctrlr midi output is also received in a midi monitor in Bidule that attests for the Note-On midi sending when I use the pre-build options for sending midi messages. But the lua method called at modulator values changes do not produce any signal.

    I tried the following:

    myMethod=function(mod, value)
    p=CtrlrMidiMessage({0x80,0x3C,0x10})
    m={0xF0; 0x18, 0x21, 0x01, 0x55, 0x16, 0xF7}
    panel:sendMidiMessageNow(CtrlrMidiMessage(m))
    panel:sendMidiMessageNow(p)
    end

    I hope both are good midi messages (the second one m is taken from working code in the forum). No new output at modulator values changes.

    Here is the version of Ctrlr I use:
    Revision = ac6a31852a8e26ddbf6a7133f87f1fd6dac8a6c4, Build date = Thu 04/24/2014, Branch = Nightly, Juce = 3.0.5, Boost = 1.52.0, Lua = 5.1.4,

    I also noticed two disturbing features, that might help:
    – midi messages go through when the midi device is plugged in the midi input of the vst although the only option in the midi menu that is checked is the “output to plugin host” option
    – Even with the working pre-build version for sending midi notes (i.e. using uibutton Midi tab), I get nothing in the ctrlr integrated midi monitor for output, only input monitor displays something

    in reply to: Sending Midi Notes to a bidule rack #23434
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    I had several attempts to solve my program sending midi notes problem.
    Finally, as I cannot see any midi output when executing
    panel:sendMidiMessageNow(midimessage)
    as the method used when modulator value is changed, I was wondering if the output is the same as the midi message option for uibuttons.
    More precisely I use Ctrlr as a vst in Bidule with no midi input or output devices but toggling each button through a learn functionnality. Non-method midi notes (the one I can access in the ui options) are then sent without any troubles to other vst. But when the method is called I get nothing new…
    Are the outputs of these two different ways to proceed not the same?

    • This reply was modified 8 years, 3 months ago by doudbassctrlr.
    in reply to: Sending Midi Notes to a bidule rack #23364
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    I have tried using a true Note-On message but it does not solve, even worth:
    I get back the “Callback error” message.

    I am not used to manipulating midi, and english either (sorry for that), but I thought I should in any case see something in the output. Does the first byte include in itself some constraints on the structure that follows?

    in reply to: Sending Midi Notes to a bidule rack #23350
    doudbassctrlr
    Participant
    • Topics: 2
    • Replies: 13
    • Total: 15

    Hello,

    # I have tried to put in “called when modulator value is changed” a method with the following “forum-inspired” code:

    messageToSend=MemoryBlock({0x90,0x3C,0x00,0x40})
    message = CtrlrMidiMessage({0x90,0x3C,0x00,0x40})
    panel:sendMidiMessageNow(message)

    I have saved it and compiled but nothing happens, I have no output…

    # I don’t understand either how I can call some specific modulator values for tests. How does it work?
    # Is it possible also to define say a live configuration using uicombos and
    according to the selected name send the appropriate set of midi notes?

    Thanks a lot for consideration
    Doud

Viewing 13 posts - 1 through 13 (of 13 total)
Ctrlr