Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

PSAM WPF Control Library

0.00/5 (No votes)
19 Jul 2018 3  
PSAM Control Library ported over to WPF

Introduction

UPDATE: This article describes an old .NET project which eventually evolved into bigger open source framework Manufaktura.Controls. You can read about it here: https://www.codeproject.com/Articles/1252423/Music-Notation-in-NET 

PSAM WPF Control Library is a WPF version of PSAM Control Library containing the IncipitViewer control for drawing musical notes which can be read from MusicXml file or added programmatically. PSAM WPF Control Library requires PSAM Control Library to run because it uses some of PSAM Control Library's classes. PSAM WPF Control Library is written in C# and XAML under Microsoft Visual Studio Express.

Using the Code

IncipitViewerWPF control requires special font to draw notes and other musical symbols. You can create your own font or use the included font Polihymnia which is based on Ben Laenen's Euterpe font and distributed under Sil Open Font Licence. Of course, you have to install the font in your fonts directory to display notes properly.

You can load a MusicXml file or add notes programmatically the same way as it is done in PSAM Control Library. Read the article about PSAM Control Library for details.

The control looks like that:

psamwpfcontrollibrary/example1.png

Because it's a WPF control, you can apply fancy effects like these:

psamwpfcontrollibrary/example2.png

psamwpfcontrollibrary/example3.png

Printing is even simpler than in PSAM Control Library. You just have to write the following code:

PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
     dialog.PrintVisual(viewer, "Test");
} 

where viewer is a IncipitViewerWPF control. Sample printout:

psamwpfcontrollibrary/example4.png

Points of Interest

Porting PSAM Control Library to WPF was quite simple. I made some changes to PSAM Control Library, namely I added a new interface IIncipitViewer which represents IncipitViewer's methods and properties and then I implemented this interface in IncipitViewerWPF class. I also moved ParseXml method from IncipitViewer to a new class called XmlParser so I didn't have to rewrite this method in IncipitViewerWPF class. To draw notes and musical symbols, I use an overridden OnRender method and a DrawingContext object.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here