// Tracks when record button is click and starts recording to JSON private void RecordButton_Click(Object sender, RoutedEventArgs e) { //AUCoefficients au = new AUCoefficients(); auJSONData auData = new auJSONData(); // Toggles on record that will start recording AU coefficients to buffer if (!isRecord) { isRecord = true; } // When record is disabled write stored AUs to JSON object else { isRecord = false; stopwatch.Stop(); JsonSerializer serializer = new JsonSerializer(); // Record AUs to object for JSON writer to convert for (int i = 0; i < timeBuffer.Count; i++) { // For each element, make sure the length of the data is in range, then add it if (i < lipRaiserBuffer.Count) { auData.A10.Add(new auJSONpoint(timeBuffer[i], lipRaiserBuffer[i])); } if (i < jawLowerBuffer.Count) { auData.A26.Add(new auJSONpoint(timeBuffer[i], jawLowerBuffer[i])); auData.A27.Add(new auJSONpoint(timeBuffer[i], lipRaiserBuffer[i])); } if (i < lipStretchBuffer.Count) { auData.A20.Add(new auJSONpoint(timeBuffer[i], lipStretchBuffer[i])); } if (i < browLowerBuffer.Count) { auData.A4.Add(new auJSONpoint(timeBuffer[i], browLowerBuffer[i])); } if (i < lipDepressBuffer.Count) { auData.A13.Add(new auJSONpoint(timeBuffer[i], lipDepressBuffer[i])); auData.A15.Add(new auJSONpoint(timeBuffer[i], lipDepressBuffer[i])); } if (i < browRaiserBuffer.Count) { auData.A2.Add(new auJSONpoint(timeBuffer[i], browRaiserBuffer[i])); } if (i < xRotation.Count) { auData.facePitch.Add(new auJSONpoint(timeBuffer[i], xRotation[i])); } if (i < yRotation.Count) { auData.faceYaw.Add(new auJSONpoint(timeBuffer[i], yRotation[i])); } if (i < zRotation.Count) { auData.faceRoll.Add(new auJSONpoint(timeBuffer[i], zRotation[i])); } } // { // "Time": [ ] // "LipRaiserAU": [ ] // "JawLowerAU": [ ] // "BrowLowerAU": [ ] // "LipDepressAU": [ ] // "BrowRaiserAU": [ ] // "XRotation": [ ] // "YRotation": [ ] // "ZRotation": [ ] // } /*au.Time = timeBuffer; * au.LipRaiserAU = lipRaiserBuffer; * au.JawLowerAU = jawLowerBuffer; * au.LipStretchAU = lipStretchBuffer; * au.BrowLowerAU = browLowerBuffer; * au.LipDepressAU = lipDepressBuffer; * au.BrowRaiserAU = browRaiserBuffer; * au.XRotation = xRotation; * au.YRotation = yRotation; * au.ZRotation = zRotation; */ // File path settings -- currently json.txt in My Documents folder string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string path = System.IO.Path.Combine(myDocuments, "json.txt"); // Writes AUCoefficients using (StreamWriter sw = new StreamWriter(path)) using (JsonWriter jw = new JsonTextWriter(sw)) { serializer.Serialize(jw, auData); } Console.WriteLine(auData); } }
// Tracks when record button is click and starts recording to JSON private void RecordButton_Click(Object sender, RoutedEventArgs e) { //AUCoefficients au = new AUCoefficients(); auJSONData auData = new auJSONData(); // Toggles on record that will start recording AU coefficients to buffer if (!isRecord) { isRecord = true; } // When record is disabled write stored AUs to JSON object else { isRecord = false; stopwatch.Stop(); JsonSerializer serializer = new JsonSerializer(); // Record AUs to object for JSON writer to convert for (int i = 0; i < timeBuffer.Count; i++){ // For each element, make sure the length of the data is in range, then add it if (i < lipRaiserBuffer.Count) { auData.A10.Add(new auJSONpoint(timeBuffer[i], lipRaiserBuffer[i])); } if (i < jawLowerBuffer.Count) { auData.A26.Add(new auJSONpoint(timeBuffer[i], jawLowerBuffer[i])); auData.A27.Add(new auJSONpoint(timeBuffer[i], lipRaiserBuffer[i])); } if (i < lipStretchBuffer.Count) { auData.A20.Add(new auJSONpoint(timeBuffer[i], lipStretchBuffer[i])); } if (i < browLowerBuffer.Count) { auData.A4.Add(new auJSONpoint(timeBuffer[i], browLowerBuffer[i])); } if (i < lipDepressBuffer.Count) { auData.A13.Add(new auJSONpoint(timeBuffer[i], lipDepressBuffer[i])); auData.A15.Add(new auJSONpoint(timeBuffer[i], lipDepressBuffer[i])); } if (i < browRaiserBuffer.Count) { auData.A2.Add(new auJSONpoint(timeBuffer[i], browRaiserBuffer[i])); } if (i < xRotation.Count) { auData.facePitch.Add(new auJSONpoint(timeBuffer[i], xRotation[i])); } if (i < yRotation.Count) { auData.faceYaw.Add(new auJSONpoint(timeBuffer[i], yRotation[i])); } if (i < zRotation.Count) { auData.faceRoll.Add(new auJSONpoint(timeBuffer[i], zRotation[i])); } } // { // "Time": [ ] // "LipRaiserAU": [ ] // "JawLowerAU": [ ] // "BrowLowerAU": [ ] // "LipDepressAU": [ ] // "BrowRaiserAU": [ ] // "XRotation": [ ] // "YRotation": [ ] // "ZRotation": [ ] // } /*au.Time = timeBuffer; au.LipRaiserAU = lipRaiserBuffer; au.JawLowerAU = jawLowerBuffer; au.LipStretchAU = lipStretchBuffer; au.BrowLowerAU = browLowerBuffer; au.LipDepressAU = lipDepressBuffer; au.BrowRaiserAU = browRaiserBuffer; au.XRotation = xRotation; au.YRotation = yRotation; au.ZRotation = zRotation; */ // File path settings -- currently json.txt in My Documents folder string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string path = System.IO.Path.Combine(myDocuments, "json.txt"); // Writes AUCoefficients using (StreamWriter sw = new StreamWriter(path)) using (JsonWriter jw = new JsonTextWriter(sw)) { serializer.Serialize(jw, auData); } Console.WriteLine(auData); } }