Пример #1
0
        public void ConstructorTest()
        {
            // Arrange
            byte[] val1 = new byte[] { 0x61 };
            byte[] val2 = new byte[] { 0x61, 0 };
            byte[] val3 = new byte[] { 0x6A, 0x6F, 0x6B, 0x65, 0x32, 0x00 };             // UTF8 v: 'joke2\0'


            // Act
            MetadataValue result1 = new MetadataValue(val1);
            MetadataValue result2 = new MetadataValue(val2);
            MetadataValue result3 = new MetadataValue(val3);

            // Assert
            CollectionAssert.AreNotEqual(val1, val2);
            CollectionAssert.AreNotEqual(val1, val3);

            Assert.IsFalse(result1.isString);
            Assert.AreEqual(val1[0], result1.bytesValue[0]);

            Assert.IsTrue(result2.isString);
            Assert.AreEqual("a", result2.stringValue);

            Assert.IsTrue(result3.isString);
            Assert.AreEqual("joke2", result3.stringValue);
        }
Пример #2
0
        public EditTrackViewModel(IList <string> paths, IMetadataService metadataService, IDialogService dialogService)
        {
            this.multipleValuesText = "<" + ResourceUtils.GetString("Language_Multiple_Values") + ">";

            this.artists      = new MetadataValue();
            this.title        = new MetadataValue();
            this.album        = new MetadataValue();
            this.albumArtists = new MetadataValue();
            this.year         = new MetadataValue();
            this.trackNumber  = new MetadataValue();
            this.trackCount   = new MetadataValue();
            this.discNumber   = new MetadataValue();
            this.discCount    = new MetadataValue();
            this.genres       = new MetadataValue();
            this.grouping     = new MetadataValue();
            this.comment      = new MetadataValue();
            this.lyrics       = new MetadataValue();
            this.artwork      = new MetadataArtworkValue();

            this.paths           = paths;
            this.metadataService = metadataService;
            this.dialogService   = dialogService;

            this.HasMultipleArtwork = false;
            this.UpdateAlbumArtwork = false;

            this.LoadedCommand = new DelegateCommand(async() => await this.GetFilesMetadataAsync());

            this.NavigateCommand = new DelegateCommand <string>((index) => Navigate(index));

            this.ExportArtworkCommand = new DelegateCommand(async() =>
            {
                if (HasArtwork)
                {
                    await SaveFileUtils.SaveImageFileAsync("cover", this.Artwork.Value);
                }
            });

            this.ChangeArtworkCommand = new DelegateCommand(async() =>
            {
                if (!await OpenFileUtils.OpenImageFileAsync(new Action <byte[]>(this.UpdateArtwork)))
                {
                    this.dialogService.ShowNotification(
                        0xe711,
                        16,
                        ResourceUtils.GetString("Language_Error"),
                        ResourceUtils.GetString("Language_Error_Changing_Image"),
                        ResourceUtils.GetString("Language_Ok"),
                        true,
                        ResourceUtils.GetString("Language_Log_File"));
                }
            });

            this.RemoveArtworkCommand = new DelegateCommand(() => this.UpdateArtwork(null));

            this.Navigate("1"); // Make sure something is displayed when the screen is shown
        }
Пример #3
0
        private static string GetOrderedMultiValueTags(MetadataValue value)
        {
            if (string.IsNullOrWhiteSpace(value.Value))
            {
                return(string.Empty);
            }

            IEnumerable <string> patchedEnumeration = MetadataUtils.PatchID3v23Enumeration(value.Values);
            IEnumerable <string> delimitedTags      = patchedEnumeration.Select(x => MetadataUtils.DelimitTag(x));

            return(string.Join(string.Empty, delimitedTags.OrderBy(x => x).ToArray()));
        }
Пример #4
0
        private void AreEqual(MetadataValue exp, MetadataValue act)
        {
            if (exp != null)
            {
                Assert.NotNull(act);

                Assert.Equal(exp.Name, act.Name);
                Assert.Equal(exp.Value, act.Value);
            }
            else
            {
                Assert.Null(act);
            }
        }
Пример #5
0
        public EditTrackViewModel(IList <TrackInfo> trackinfos, IMetadataService metadataService, IDialogService dialogService)
        {
            this.multipleValuesText = ResourceUtils.GetStringResource("Language_Multiple_Values");

            this.artists      = new MetadataValue();
            this.title        = new MetadataValue();
            this.album        = new MetadataValue();
            this.albumArtists = new MetadataValue();
            this.year         = new MetadataValue();
            this.trackNumber  = new MetadataValue();
            this.trackCount   = new MetadataValue();
            this.discNumber   = new MetadataValue();
            this.discCount    = new MetadataValue();
            this.genres       = new MetadataValue();
            this.grouping     = new MetadataValue();
            this.comment      = new MetadataValue();
            this.artwork      = new MetadataArtworkValue();

            this.trackInfos      = trackinfos;
            this.metadataService = metadataService;
            this.dialogService   = dialogService;

            this.HasMultipleArtwork = false;
            this.UpdateAlbumArtwork = false;

            this.LoadedCommand = new DelegateCommand(async() => await this.GetFilesMetadataAsync());

            this.ChangeArtworkCommand = new DelegateCommand(async() =>
            {
                if (!await OpenFileUtils.OpenImageFileAsync(new Action <string, byte[]>(this.UpdateArtwork)))
                {
                    this.dialogService.ShowNotification(
                        0xe711,
                        16,
                        ResourceUtils.GetStringResource("Language_Error"),
                        ResourceUtils.GetStringResource("Language_Error_Changing_Image"),
                        ResourceUtils.GetStringResource("Language_Ok"),
                        true,
                        ResourceUtils.GetStringResource("Language_Log_File"));
                }
            });


            this.RemoveArtworkCommand = new DelegateCommand(() => this.UpdateArtwork(String.Empty, null));
        }
Пример #6
0
        private async Task SaveLyricsInAudioFileAsync()
        {
            this.IsEditing = false;
            this.ParseLyrics(this.lyrics);

            if (this.track == null)
            {
                return;
            }

            // Save to the file
            var fmd = await this.metadataService.GetFileMetadataAsync(this.track.Path);

            var lyricsMetaDataValue = new MetadataValue(this.lyrics.Text);

            lyricsMetaDataValue.Value = this.lyrics.Text;
            fmd.Lyrics = lyricsMetaDataValue;
            await this.metadataService.UpdateTracksAsync(new List <FileMetadata> {
                fmd
            }, false);
        }
Пример #7
0
        private async Task GetFilesMetadataAsync()
        {
            List <FileMetadata> fileMetadatas = new List <FileMetadata>();

            try
            {
                foreach (string path in this.paths)
                {
                    fileMetadatas.Add(await this.metadataService.GetFileMetadataAsync(path));
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("An error occured while getting the metadata from the files. Exception: {0}", ex.Message);
            }

            if (fileMetadatas.Count == 0)
            {
                return;
            }

            await Task.Run(() =>
            {
                try
                {
                    // Artists
                    List <string> distinctArtists = fileMetadatas.Select((f) => f.Artists.Value).Distinct().ToList();
                    this.Artists = new MetadataValue(distinctArtists.Count == 1 ? distinctArtists.First() : this.multipleValuesText);

                    // Title
                    List <string> distinctTitles = fileMetadatas.Select((f) => f.Title.Value).Distinct().ToList();
                    this.Title = new MetadataValue(distinctTitles.Count == 1 ? distinctTitles.First() : this.multipleValuesText);

                    // Album
                    List <string> distinctAlbums = fileMetadatas.Select((f) => f.Album.Value).Distinct().ToList();
                    this.Album = new MetadataValue(distinctAlbums.Count == 1 ? distinctAlbums.First() : this.multipleValuesText);

                    // AlbumArtists
                    List <string> distinctAlbumArtists = fileMetadatas.Select((f) => f.AlbumArtists.Value).Distinct().ToList();
                    this.AlbumArtists = new MetadataValue(distinctAlbumArtists.Count == 1 ? distinctAlbumArtists.First() : this.multipleValuesText);

                    // Year
                    List <string> distinctYears = fileMetadatas.Select((f) => f.Year.Value).Distinct().ToList();
                    this.Year = new MetadataValue(distinctYears.Count == 1 ? distinctYears.First().ToString() : this.multipleValuesText);

                    // TrackNumber
                    List <string> distinctTrackNumbers = fileMetadatas.Select((f) => f.TrackNumber.Value).Distinct().ToList();
                    this.TrackNumber = new MetadataValue(distinctTrackNumbers.Count == 1 ? distinctTrackNumbers.First().ToString() : this.multipleValuesText);

                    // TrackCount
                    List <string> distinctTrackCounts = fileMetadatas.Select((f) => f.TrackCount.Value).Distinct().ToList();
                    this.TrackCount = new MetadataValue(distinctTrackCounts.Count == 1 ? distinctTrackCounts.First().ToString() : this.multipleValuesText);

                    // DiscNumber
                    List <string> distinctDiscNumbers = fileMetadatas.Select((f) => f.DiscNumber.Value).Distinct().ToList();
                    this.DiscNumber = new MetadataValue(distinctDiscNumbers.Count == 1 ? distinctDiscNumbers.First().ToString() : this.multipleValuesText);

                    // DiscCount
                    List <string> distinctDiscCounts = fileMetadatas.Select((f) => f.DiscCount.Value).Distinct().ToList();
                    this.DiscCount = new MetadataValue(distinctDiscCounts.Count == 1 ? distinctDiscCounts.First().ToString() : this.multipleValuesText);

                    // Genres
                    List <string> distinctGenres = fileMetadatas.Select((f) => f.Genres.Value).Distinct().ToList();
                    this.Genres = new MetadataValue(distinctGenres.Count == 1 ? distinctGenres.First() : this.multipleValuesText);

                    // Grouping
                    List <string> distinctGroupings = fileMetadatas.Select((f) => f.Grouping.Value).Distinct().ToList();
                    this.Grouping = new MetadataValue(distinctGroupings.Count == 1 ? distinctGroupings.First() : this.multipleValuesText);

                    // Comment
                    List <string> distinctComments = fileMetadatas.Select((f) => f.Comment.Value).Distinct().ToList();
                    this.Comment = new MetadataValue(distinctComments.Count == 1 ? distinctComments.First() : this.multipleValuesText);

                    // Lyrics
                    List <string> distinctLyrics = fileMetadatas.Select((f) => f.Lyrics.Value).Distinct().ToList();
                    this.lyrics = new MetadataValue(distinctLyrics.Count == 1 ? distinctLyrics.First() : this.multipleValuesText);

                    // Artwork
                    this.GetArtwork(fileMetadatas);
                }
                catch (Exception ex)
                {
                    LogClient.Error("An error occured while parsing the metadata. Exception: {0}", ex.Message);
                }
            });
        }
Пример #8
0
    // During initialization, we will allocate all required objects, and set up our custom instance data.
    void Start()
    {
        // Create the BatchRendererGroup and register assets
        m_BRG        = new BatchRendererGroup(this.OnPerformCulling, IntPtr.Zero);
        m_MeshID     = m_BRG.RegisterMesh(mesh);
        m_MaterialID = m_BRG.RegisterMaterial(material);

        // Create the buffer that holds our instance data
        m_InstanceData = new GraphicsBuffer(GraphicsBuffer.Target.Raw,
                                            (kExtraBytes + kBytesPerInstance * kNumInstances) / sizeof(int),
                                            sizeof(int));

        // Place one zero matrix at the start of the instance data buffer, so loads from address 0 will return zero
        var zero = new Matrix4x4[1] {
            Matrix4x4.zero
        };

        // Create transform matrices for our three example instances
        var matrices = new Matrix4x4[kNumInstances]
        {
            Matrix4x4.Translate(new Vector3(-2, 0, 0)),
            Matrix4x4.Translate(new Vector3(0, 0, 0)),
            Matrix4x4.Translate(new Vector3(2, 0, 0)),
        };

        // Convert the transform matrices into the packed format expected by the shader
        var objectToWorld = new PackedMatrix[kNumInstances]
        {
            new PackedMatrix(matrices[0]),
            new PackedMatrix(matrices[1]),
            new PackedMatrix(matrices[2]),
        };

        // Also create packed inverse matrices
        var worldToObject = new PackedMatrix[kNumInstances]
        {
            new PackedMatrix(matrices[0].inverse),
            new PackedMatrix(matrices[1].inverse),
            new PackedMatrix(matrices[2].inverse),
        };

        // Make all instances have unique colors
        var colors = new Vector4[kNumInstances]
        {
            new Vector4(1, 0, 0, 1),
            new Vector4(0, 1, 0, 1),
            new Vector4(0, 0, 1, 1),
        };

        // In this simple example, the instance data is placed into the buffer like this:
        // Offset | Description
        //      0 | 64 bytes of zeroes, so loads from address 0 return zeroes
        //     64 | 32 uninitialized bytes to make working with SetData easier, otherwise unnecessary
        //     96 | unity_ObjectToWorld, three packed float3x4 matrices
        //    240 | unity_WorldToObject, three packed float3x4 matrices
        //    384 | _BaseColor, three float4s

        // Compute start addresses for the different instanced properties. unity_ObjectToWorld starts
        // at address 96 instead of 64, because the computeBufferStartIndex parameter of SetData
        // is expressed as source array elements, so it is easier to work in multiples of sizeof(PackedMatrix).
        uint byteAddressObjectToWorld = kSizeOfPackedMatrix * 2;
        uint byteAddressWorldToObject = byteAddressObjectToWorld + kSizeOfPackedMatrix * kNumInstances;
        uint byteAddressColor         = byteAddressWorldToObject + kSizeOfPackedMatrix * kNumInstances;

        // Upload our instance data to the GraphicsBuffer, from where the shader can load them.
        m_InstanceData.SetData(zero, 0, 0, 1);
        m_InstanceData.SetData(objectToWorld, 0, (int)(byteAddressObjectToWorld / kSizeOfPackedMatrix), objectToWorld.Length);
        m_InstanceData.SetData(worldToObject, 0, (int)(byteAddressWorldToObject / kSizeOfPackedMatrix), worldToObject.Length);
        m_InstanceData.SetData(colors, 0, (int)(byteAddressColor / kSizeOfFloat4), colors.Length);

        // Set up metadata values to point to the instance data. Set the most significant bit 0x80000000 in each,
        // which instructs the shader that the data is an array with one value per instance, indexed by the instance index.
        // Any metadata values used by the shader and not set here will be zero. When such a value is used with
        // UNITY_ACCESS_DOTS_INSTANCED_PROP (i.e. without a default), the shader will interpret the
        // 0x00000000 metadata value so that the value will be loaded from the start of the buffer, which is
        // where we uploaded the matrix "zero" to, so such loads are guaranteed to return zero, which is a reasonable
        // default value.
        var metadata = new NativeArray <MetadataValue>(3, Allocator.Temp);

        metadata[0] = new MetadataValue {
            NameID = Shader.PropertyToID("unity_ObjectToWorld"), Value = 0x80000000 | byteAddressObjectToWorld,
        };
        metadata[1] = new MetadataValue {
            NameID = Shader.PropertyToID("unity_WorldToObject"), Value = 0x80000000 | byteAddressWorldToObject,
        };
        metadata[2] = new MetadataValue {
            NameID = Shader.PropertyToID("_BaseColor"), Value = 0x80000000 | byteAddressColor,
        };

        // Finally, create a batch for our instances, and make the batch use the GraphicsBuffer with our
        // instance data, and the metadata values that specify where the properties are. Note that
        // we do not need to pass any batch size here.
        m_BatchID = m_BRG.AddBatch(metadata, m_InstanceData.bufferHandle);
    }