<commit_before><?php

class MelodyController {

	static $result;
	static $results;
	static $patternArray;
	static $xmlArray;
	static $xmlPositionArray;
	static $once;
	// static $restDuration;
	static $noteCounter;

	function __construct() {
	

	}

	public function search($pattern) {
	
		$p = $pattern[0]->notes;
		self::$patternArray = array();
		self::$results = array();

		//get note intervals of pattern
		foreach ($p as $note) {
			if($note->type == "note"){
				$interval = PatternController::getInterval($note);
				$obj = new stdClass();
				$obj->interval = $interval;
				$obj->type = $note->pitch->type;
				if(isset($note->pitch->beam)){
					if($note->pitch->beam != false){
						$obj->beam = (string)$note->pitch->beam;
					}
				}
				// else if dotted note
				if(isset($note->pitch->dot)){
					if($note->pitch->dot == true){
						$obj->dot = "1";
					}
				}
				array_push(self::$patternArray, $obj);
			}else{
				array_push(self::$patternArray, $note->duration);
			}
		}

		//get user uploads & file_id's & file_url
		$user = User::find(Cookie::get('user_id'));
		$user->uploads->each(function($upload) {
			$xml = simplexml_load_file($upload->url);
			$file_id = $upload->id;
			$file_url = $upload->url;

			self::$once = true;
			self::$xmlArray = array(); 
			self::$xmlPositionArray = array();
			self::$result = new stdClass();
			self::$result->occurences = array();

			$parts = $xml->xpath("//part");


			foreach($parts as $part){
				self::$noteCounter = 0;
				self::$once = true;
				for($i = 0; $i < count($part->measure); $i++){
					
					if($i == 0){
						//get division for calculation of rest duration once
						$partDivision = $part->measure[$i]->attributes->divisions;
						//get beat-type for calculation of rest duration once
						$partBeatType = $part->measure[$i]->attributes->time->{'beat-type'};
					}

					//get beat-type changes within measures
					if($i>0){ //no changes within first round
						// if changes occure
						if(isset($part->measure[$i]->attributes->time->{'beat-type'})){
							// get changes
							$partBeatType = $part->measure[$i]->attributes->time->{'beat-type'};
						}
					}
					for($j = 0; $j < count($part->measure[$i]->note); $j++){
						self::$noteCounter++;
						$n = $part->measure[$i]->note[$j];

						if(self::$once){
							self::$once = false;
							$lastVoice = $part->measure[$i]->note[$j]->voice;
						}

						if((int)$n->voice == (int)$lastVoice){
							$pitch = new stdClass();
							$pitch->step = $n->pitch->step;
							$pitch->alter = $n->pitch->alter;
							$pitch->octave = $n->pitch->octave;


							$note = new stdClass();
							$note->pitch = $pitch;
							$note->voice = $n->voice;
							// $note->type = $n->type;
							$note->position = self::$noteCounter;

							// if note
							if(!$n->rest && !isset($n->chord)){

								$obj = new stdClass();
								$obj->interval = PatternController::getInterval($note);
								$obj->type = $n->type;

								if(isset($n->{'time-modification'})){
									$obj->beam = (string)$n->beam[0];
								}
								// else if dotted note
								//check with "!isnull" because n->dot === object(SimpleXMLElement)#226 (0) { } 
								elseif(!is_null($n->dot)){
									$obj->dot = "1";
								}

								array_push(self::$xmlArray, $obj);
								array_push(self::$xmlPositionArray, $note->position);

							}
							// else if rest
							else{
								// calculate rest duration
								try{
									$restDurationFloat = (float)((int)$n->duration / (int)$partDivision / (int)$partBeatType);
								} catch (Exception $e) {
// echo"<br><hr>n->duration: <br>";
// var_dump($n->duration);
// echo"<br>partDivision: <br>";
// var_dump($partDivision);
// echo"<br>partBeatType: <br>";
// var_dump($partBeatType);
								    Log::error('Exception abgefangen: ',  array('error' => $e->getMessage());
								}

								// rest durations: "whole" "half" "quarter" "eighth" "16th" "32nd" "64th"
								// determine 'type'
								if ($restDurationFloat == 1){
									$restDuration = "whole";
								} elseif ($restDurationFloat == 0.75) {<commit_msg>fix melody controller syntax err<commit_after><?php

class MelodyController {

	static $result;
	static $results;
	static $patternArray;
	static $xmlArray;
	static $xmlPositionArray;
	static $once;
	// static $restDuration;
	static $noteCounter;

	function __construct() {
	

	}

	public function search($pattern) {
	
		$p = $pattern[0]->notes;
		self::$patternArray = array();
		self::$results = array();

		//get note intervals of pattern
		foreach ($p as $note) {
			if($note->type == "note"){
				$interval = PatternController::getInterval($note);
				$obj = new stdClass();
				$obj->interval = $interval;
				$obj->type = $note->pitch->type;
				if(isset($note->pitch->beam)){
					if($note->pitch->beam != false){
						$obj->beam = (string)$note->pitch->beam;
					}
				}
				// else if dotted note
				if(isset($note->pitch->dot)){
					if($note->pitch->dot == true){
						$obj->dot = "1";
					}
				}
				array_push(self::$patternArray, $obj);
			}else{
				array_push(self::$patternArray, $note->duration);
			}
		}

		//get user uploads & file_id's & file_url
		$user = User::find(Cookie::get('user_id'));
		$user->uploads->each(function($upload) {
			$xml = simplexml_load_file($upload->url);
			$file_id = $upload->id;
			$file_url = $upload->url;

			self::$once = true;
			self::$xmlArray = array(); 
			self::$xmlPositionArray = array();
			self::$result = new stdClass();
			self::$result->occurences = array();

			$parts = $xml->xpath("//part");


			foreach($parts as $part){
				self::$noteCounter = 0;
				self::$once = true;
				for($i = 0; $i < count($part->measure); $i++){
					
					if($i == 0){
						//get division for calculation of rest duration once
						$partDivision = $part->measure[$i]->attributes->divisions;
						//get beat-type for calculation of rest duration once
						$partBeatType = $part->measure[$i]->attributes->time->{'beat-type'};
					}

					//get beat-type changes within measures
					if($i>0){ //no changes within first round
						// if changes occure
						if(isset($part->measure[$i]->attributes->time->{'beat-type'})){
							// get changes
							$partBeatType = $part->measure[$i]->attributes->time->{'beat-type'};
						}
					}
					for($j = 0; $j < count($part->measure[$i]->note); $j++){
						self::$noteCounter++;
						$n = $part->measure[$i]->note[$j];

						if(self::$once){
							self::$once = false;
							$lastVoice = $part->measure[$i]->note[$j]->voice;
						}

						if((int)$n->voice == (int)$lastVoice){
							$pitch = new stdClass();
							$pitch->step = $n->pitch->step;
							$pitch->alter = $n->pitch->alter;
							$pitch->octave = $n->pitch->octave;


							$note = new stdClass();
							$note->pitch = $pitch;
							$note->voice = $n->voice;
							// $note->type = $n->type;
							$note->position = self::$noteCounter;

							// if note
							if(!$n->rest && !isset($n->chord)){

								$obj = new stdClass();
								$obj->interval = PatternController::getInterval($note);
								$obj->type = $n->type;

								if(isset($n->{'time-modification'})){
									$obj->beam = (string)$n->beam[0];
								}
								// else if dotted note
								//check with "!isnull" because n->dot === object(SimpleXMLElement)#226 (0) { } 
								elseif(!is_null($n->dot)){
									$obj->dot = "1";
								}

								array_push(self::$xmlArray, $obj);
								array_push(self::$xmlPositionArray, $note->position);

							}
							// else if rest
							else{
								// calculate rest duration
								try{
									$restDurationFloat = (float)((int)$n->duration / (int)$partDivision / (int)$partBeatType);
								} catch (Exception $e) {
// echo"<br><hr>n->duration: <br>";
// var_dump($n->duration);
// echo"<br>partDivision: <br>";
// var_dump($partDivision);
// echo"<br>partBeatType: <br>";
// var_dump($partBeatType);
								    Log::error('Exception abgefangen: ',  array('error' => $e->getMessage()));
								}

								// rest durations: "whole" "half" "quarter" "eighth" "16th" "32nd" "64th"
								// determine 'type'
								if ($restDurationFloat == 1){
									$restDuration = "whole";
								} elseif ($restDurationFloat == 0.75) {
{'fraction_non_alphanumeric': 0.2028301886792453, 'fraction_numerical': 0.005563618771165941, 'mean_word_length': 2.66371289322109, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 183, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6184067', 'n_tokens_mistral': 3744, 'n_tokens_neox': 2722, 'n_words': 530}