In this article I want to introduce you the new functionalities from the MBS Xojo Plugins in version 20.1.
Data from Images
The classes JPEGImporterMBS, GMImageMBS and GM16ImageMBS got the new property ExifThumbnail. This property extracts an embedded thumbnail in EXIF data and return it as a string. With this string we can use the method getData method of the Picture class or our JPEG functions to decompress and display the thumbnail.
The class JPEGImporterMBS got the ExifOrientation property that queries the orientation from the Exif data. We receive the orientation as an integer and you can use this number to determine and adjust the alignment if necessary.
The classes GMImageMBS and GM16ImageMBS include the new shared method FontMap. We can use this method to find out which fonts are currently available. The method can also help us to debug and find out the reason why a font is not loaded. The function returns a string with a XML structure.
Timecode for Audio (LTC)
If audio streams need to be synchronized, you usually use time codes embedded in the audio. With the LTC library, we now provide classes that can decode and encode time code for audio streams
Port audio Stream
In the plugin we have classes to use the open source PortAudio library in Xojo. To make it easier to use, we added the read and write methods to the PortAudioStreamBaseMBS class. For buffered streams this may help to easier send/receive audio samples.
JavaScript
In the last version of the MBS Xojo Plugins we introduce the JavaScriptEngineMBS class which allows you to execute JavaScript code in your projects. Now we extended the class with some new methods and properties.
You can run JavaScript functions in several threads. For this we use the CallFunctionMT method. The work is performed in a preemptive thread, so this function does not block the application and can yield time to other Xojo threads. It must be called in a Xojo thread to enjoy the benefits. If it is called in the main thread it will be blocking, but keeps other background threads running. The parameters passed to the function are automatically adjusted by the function, i.e. if a function expects more parameters, undefined values are used to fill up. If more parameters are passed, additional ones are dropped
It is possible to execute JavaScript code directly in threads using the “EvaluateMT” method. Just pass a piece of JavaScript code and evaluate it thread friendly.
The method Now returns us the count of milliseconds since the 1st January 1970. So we can determine the current time in combination with the TimeToDateComponents method. This function returns us a timestamp with the format YYYY-MM-DD HH:MM:SS. Here you see the script to query the current time.
[code]Dim j As New JavaScriptEngineMBS
Dim t As Double = j.Now
Dim d1 As JavaScriptDateComponentsMBS = j.TimeToDateComponents(t)
Dim s1 As String = d1.SQLDateTime
MsgBox str(s1)[/code]
If you want to transform a date in that millisecond format you can set the date as an object of the new JavaScriptDateComponentsMBS class. That can looks like that:
[code]Dim js As New JavaScriptEngineMBS
Dim Date As New JavaScriptDateComponentsMBS
Date.Year = 1992
Date.Month = 07
Date.day = 15
MsgBox " Time: " + Str(js.DateComponentsToTime(date))[/code]
We have also added counting properties that query the the number of objects and global strings. In an empty JavaScript environment there are already about 1000 strings and about 400 objects. So if you want to find out how many objects and strings are added, you have to subtract the base amounts.
New functions for Mac users
The MBS Xojo Plugins in version 10.1 offers some more new features for Mac users:
NSCalendar enhancements
Further enhancements are available for Apple Calendar. With the method dateFromComponents from the NSCalendarMBS class we transform a NSDateComponetsMBS to a date. With the method dateByAddingComponents we add date components thats are defined as NSDateComponetsMBS object. For example we have the date 07-15-1992 as date we can save it in a NSDateComponentsMBS object and transform it with dateFromComponents to a date. Then I want to add 16 years to that date. Because that I need a second instance of the NSDateComponentsMBS class with a property year with the value 16. Then we add the years with the dateByAddingComponents method. The code you can looks like that.
[code]Dim comp As New NSDateComponentsMBS
comp.day = 15
comp.month = 7
comp.year = 1992
Dim year As New NSDateComponentsMBS
year.year = 16
Dim cal As New NSCalendarMBS
Dim z As Date = cal.dateFromComponents(comp)
Dim sweetsixteen As Date = cal.dateByAddingComponents(year, z)
MsgBox str(sweetsixteen)[/code]
There is another method called “isValidDateInCalendar” from the NSDateComponentsMBS class. With this method you can check if there exists a calendar entry with the combined properties of the NSDateComponents object.
Webkit 2
We have a new class WKHTTPCookieStoreMBS that manages the HTTP cookies associated with a particular WKWebsiteDataStore. You can use the class e.g. to create an array of all cookies and then read them one by one via their indexes.
Example code:
Dim CookieStore As WKHTTPCookieStoreMBS = WKWebViewControlMBS1.WKWebView.HTTPCookieStore
Dim cookies() As NSHTTPCookieMBS = CookieStore.AllCookies
Dim cookie As NSHTTPCookieMBS = cookies(0)
An other new class is the WKPreferencesMBS class. The objects from this class encapsulates the preference settings for a web view. The preferences object associated with a web view is specified by its web view configuration. You can allow the use of Java and JavaScript code and make settings such as minimum font size.
The objects of the WKWebViewConfigurationMBS class supply a collection of properties used to initialize a web view. With this class you can determine how soon a webpage is rendered, how media playback is handled, the granularity of items that the user can select and many other options.
News from the AVFoundation
We support functionalities for Apple’s latest audio/video framework for recording and playback. In the latest version of the plugins we have added a great AVRouteDetectorMBS which allows you to detects the presences of media playback routes. When route detection is enabled, AVRouteDetector reports whether multiple playback routes have been detected. Belonging to this class there is a control that displays controls for picking playback routes. By default, route detection is disabled. For this functionality you need Mac MacOS 10.15 or newer.
News from the topic MIDI
The new properties from the topic MIDI in the class MidiThruConnectionParamsMBS set the maximum (HighVelocity) and minimum velocity (LowVelocity). All events with a velocity outside this range will be filtered.