Exemplo n.º 1
0
		def getAdditionalImportsAndDeclarationsForParentScope(parentNode, argumentSymbolNames):
			additionalImports = []
			additionalDeclarations = []
			additionalDummies = []
			dependantTemplatesAndEntries = getDomainDependantTemplatesAndEntries(cgDoc, parentNode)
			for template, entry in dependantTemplatesAndEntries:
				dependantName = entry.firstChild.nodeValue
				if dependantName in argumentSymbolNames:
					continue #in case user is working with slices and passing them to different symbols inside the kernel, he has to manage that stuff manually
				symbol = currSymbolsByName.get(dependantName)
				if symbol == None:
					logging.debug("while analyzing additional kernel parameters: symbol %s was not available yet for parent %s, so it was loaded freshly" %(
						dependantName,
						parentNode.getAttribute('name')
					))
					symbol = Symbol(
			            dependantName,
			            template,
			            symbolEntry=entry,
			            scopeNode=parentNode,
			            analysis=getAnalysisForSymbol(symbolAnalysisByRoutineNameAndSymbolName, parentNode.getAttribute('name'), dependantName),
			            parallelRegionTemplates=parallelRegionTemplates
			        )
				symbol.loadRoutineNodeAttributes(parentNode, parallelRegionTemplates)
				if symbol.isDummySymbolForRoutine(routineName=parentNode.getAttribute('name')):
					continue #already passed manually
				if symbol.declarationType == DeclarationType.LOCAL_MODULE_SCALAR \
				and routineNode.getAttribute('module') == moduleNode.getAttribute('name'):
					additionalDeclarations.append(symbol)
				elif (symbol.analysis and symbol.analysis.isModuleSymbol) or symbol.declarationType == DeclarationType.FOREIGN_MODULE_SCALAR:
					additionalImports.append(symbol)
				elif symbol.declarationType == DeclarationType.LOCAL_ARRAY:
					additionalDummies.append(symbol)
			return additionalImports, additionalDeclarations, additionalDummies
    def mutate(self, WEIGHTS, chords, count=1):
        """Mutates a random symbol

        Arguments:
        WEIGHTS - the default weights
        chords -- the possible chords
        count -- the number of symbols to mutate
        """
        for _ in range(count):
            i = self.select()
            beats_left = convert_to_float(self.symbols[i - 1].length)
            note_weights = self.set_weights(WEIGHTS, chords)

            if random.randint(1, 100) < 50:
                self.pop(i - 1)
            else:
                beats_left -= convert_to_float(self.symbols[i - 1].mutate(
                    WEIGHTS, note_weights, beats_left))

            while beats_left > 0:
                if random.randint(1, 100) < 50 or len(self.symbols) == 0:
                    s = Symbol()
                    beats_left -= convert_to_float(
                        s.gen(WEIGHTS, note_weights, beats_left))
                    if len(self.symbols) > 0:
                        i = self.select()
                    self.insert(i - 1, s)
                else:
                    i = self.select()
                    beats_left += convert_to_float(self.symbols[i - 1].length)
                    beats_left -= convert_to_float(self.symbols[i - 1].mutate(
                        WEIGHTS, note_weights, beats_left))
Exemplo n.º 3
0
    def add(self, name, value, dataType, environment, references, line,
            column):
        self._idSymbol += 1

        self._symbols.append(
            Symbol(self._idSymbol, name, value, dataType, environment,
                   references, line, column))
    def parse_string(self, string):
        """Parse and convert a string into a list of measures

        Arguments:
        string -- the string to parse
        """
        end = string[1:].index('"')
        self.chord = string[1:end + 1]
        self.symbols = [Symbol(string=s) for s in string[end + 3:].split(" ")]
Exemplo n.º 5
0
    def declaration_handler(self):
        var_table = []
        category = self.input[0].identifier
        isparam = False
        self.input.pop(0)

        while self.input[0].identifier not in semanticdeclarations and self.input[0].identifier != 6:
            if self.input[0].identifier in semantictypes:
                if self.input[0].identifier == 9:
                    for var in var_table:
                        var.type = 9
                        self.include(var)
                    while self.input[0].identifier not in semantictypes:
                        self.input.pop(0)
                    self.input.pop(0)
                elif self.input[0].identifier == 8:
                    for var in var_table:
                        var.type = 8
                        self.include(var)
                var_table.clear()
            if self.input[0].identifier == 25:
                symbol = Symbol()
                symbol.scope = self.input[0].scope
                symbol.name = self.input[0].value.upper()
                symbol.line = self.input[0].line
                if category in [2, 3]:
                    symbol.category = category
                    if category == 3:
                        symbol.type = 8
                    self.include(symbol)
                elif category == 4:
                    symbol.category = category
                    var_table.append(symbol)
                elif category == 5:
                    if isparam:
                        symbol.category = 6
                        var_table.append(symbol)
                    else:
                        self.scope = self.input[0].scope
                        symbol.category = category
                        self.include(symbol)
                        isparam = True
            self.input.pop(0)
    def gen(self, WEIGHTS, chords, key, note_count, note_bar, bars):
        """Generate a random list of symbols for the measure
        that fit in the necessary time signature

        Arguments:
        WEIGHTS -- the default weights
        chords -- the possible chords
        key -- the tune's key
        note_count -- needed for time signature
        note_bar -- needed for time signature
        bars -- needed for time signature
        """
        self.symbols = []
        beats_left = (note_count * 1 / bars) * note_bar
        note_weights = self.set_weights(WEIGHTS, chords)

        while beats_left > 0:
            s = Symbol()
            beats_left -= convert_to_float(
                s.gen(WEIGHTS, note_weights, beats_left))
            self.append(s)
Exemplo n.º 7
0
		def getAdditionalImportsAndDeclarationsForParentScope(parentNode, argumentSymbolNames):
			additionalImports = []
			additionalDeclarations = []
			additionalDummies = []
			dependantTemplatesAndEntries = getDomainDependantTemplatesAndEntries(parentNode.ownerDocument, parentNode)
			for template, entry in dependantTemplatesAndEntries:
				dependantName = entry.firstChild.nodeValue
				if dependantName in argumentSymbolNames:
					continue #in case user is working with slices and passing them to different symbols inside the kernel, he has to manage that stuff manually
				symbol = currRoutine.symbolsByName.get(uniqueIdentifier(dependantName, currRoutine.name))
				if not symbol:
					symbol = currRoutine.symbolsByName.get(uniqueIdentifier(dependantName, currRoutine._parentModule().name))
				if not symbol:
					symbol = currRoutine.symbolsByName.get(dependantName)
				if not symbol:
					logging.debug("while analyzing additional kernel parameters: symbol %s was not available yet for parent %s, so it was loaded freshly;\nCurrent symbols:%s\n" %(
						dependantName,
						parentNode.getAttribute('name'),
						currRoutine.symbolsByName.keys()
					))
					symbol = Symbol(
						dependantName,
						template,
						symbolEntry=entry,
						scopeNode=parentNode,
						analysis=getAnalysisForSymbol(symbolAnalysisByRoutineNameAndSymbolName, parentNode.getAttribute('name'), dependantName),
						parallelRegionTemplates=callee.parallelRegionTemplates
					)
					symbol.loadRoutineNodeAttributes(parentNode, callee.parallelRegionTemplates)
					updateTypeParameterProperties(symbol, currRoutine.symbolsByName.values())
				if symbol.isTypeParameter:
					continue
				if symbol.isDummySymbolForRoutine(routineName=parentNode.getAttribute('name')):
					continue #already passed manually
				isModuleSymbol = symbol.declarationType in [
					DeclarationType.LOCAL_MODULE_SCALAR,
					DeclarationType.MODULE_ARRAY,
					DeclarationType.MODULE_ARRAY_PASSED_IN_AS_ARGUMENT
				]
				if isModuleSymbol and currRoutine.node.getAttribute('module') == symbol.sourceModule:
					logging.debug("decl added for %s" %(symbol))
					additionalDeclarations.append(symbol)
				elif (symbol.analysis and symbol.analysis.isModuleSymbol) \
				or (isModuleSymbol and currRoutine.node.getAttribute('module') != symbol.sourceModule) \
				or symbol.declarationType == DeclarationType.FOREIGN_MODULE_SCALAR:
					if symbol.sourceModule != callee.parentModule.node.getAttribute('name'):
						foreignModuleNode = moduleNodesByName[symbol.sourceModule]
						symbol.loadImportInformation(parentNode.ownerDocument, foreignModuleNode)
					logging.debug("import added for %s" %(symbol))
					additionalImports.append(symbol)
				elif symbol.declarationType in [
					DeclarationType.LOCAL_ARRAY,
					DeclarationType.LOCAL_SCALAR,
					DeclarationType.OTHER_SCALAR
				]:
					logging.debug("dummy added for %s" %(symbol))
					additionalDummies.append(symbol)
			return additionalImports, additionalDeclarations, additionalDummies
Exemplo n.º 8
0
    def makeDummySymbol(self, cgDoc, module, routine):
        from models.symbol import Symbol
        from tools.metadata import getDomainDependantTemplatesAndEntries

        routineNode = routine.node
        self.assertEqual(routineNode.tagName, "routine")

        templatesAndEntries = getDomainDependantTemplatesAndEntries(
            cgDoc, routineNode)
        self.assertEqual(len(templatesAndEntries), 1)

        template, entry = templatesAndEntries[0]
        symbol = Symbol("testSymbol",
                        template,
                        symbolEntry=entry,
                        scopeNode=routineNode,
                        analysis=None,
                        parallelRegionTemplates=[],
                        globalParallelDomainNames={})
        routine.loadSymbolsByName({"testSymbol": symbol})
        return symbol
Exemplo n.º 9
0
                       '"G" c3 B3 A2 B|"F" c3 B2 c d2 G|"C" e2 d c2 B c2 d|'
                       '"Am" e3 ^d3 B2 =d|"G" c3 B3 A2 B|"F" c3 B2 A G2 B|'
                       '"Am" A3 z2 A A2 c|"Am" e3 ^d3 B2 =d|"G" c3 B3 A2 B|'
                       '"F" c3 B2 c d2 G|"C" e2 d c2 B c2 d|"Am" e3 ^d3 B2 =d|'
                       '"G" c3 B3 A2 B|"F" c3 B2 A G2 B|"Am" A3 A,6'))

Ode_to_joy = Tune(
    title="Ode to Joy",
    note_count=4,
    bars=4,
    note_duration=1,
    note_bar=4,
    key='C',
    measures=[
        Measure(chord="C",
                symbols=[Symbol("E"),
                         Symbol("E"),
                         Symbol("F"),
                         Symbol("G")]),
        Measure(chord="C",
                symbols=[Symbol("G"),
                         Symbol("F"),
                         Symbol("E"),
                         Symbol("D")]),
        Measure(chord="C",
                symbols=[Symbol("C"),
                         Symbol("C"),
                         Symbol("D"),
                         Symbol("E")]),
        Measure(
            chord="G",