10524a6a8Smahlzeit/*! 26ac7032dSJohn Scipione \mainpage Welcome to the Haiku Book 36ac7032dSJohn Scipione 46ac7032dSJohn Scipione Below you will find documentation on the Application Programming 56ac7032dSJohn Scipione Interface (API) of the Haiku operating system. This API describes 66ac7032dSJohn Scipione the internals of the operating system allowing developers to write 76ac7032dSJohn Scipione native C++ applications and device drivers. See the 81de2d728SAugustin Cavalier <a href="https://api.haiku-os.org">online version</a> for the most 96ac7032dSJohn Scipione updated version of this document. If you would like to help contribute 104d556706SAugustin Cavalier contact the <a href="https://www.freelists.org/list/haiku-doc">documentation 116ac7032dSJohn Scipione mailing list</a>. For guidelines on how to help document the API see 126ac7032dSJohn Scipione the \link apidoc Documenting the API\endlink page. A list of 136ac7032dSJohn Scipione contributors can be found \ref credits page. Documenting the API is 146ac7032dSJohn Scipione an ongoing process so contributions are greatly appreciated. 156ac7032dSJohn Scipione 166ac7032dSJohn Scipione The Haiku API is based on the BeOS R5 API but changes and additions have 176ac7032dSJohn Scipione been included where appropriate. Important compatibility differences are 186ac7032dSJohn Scipione detailed on the \ref compatibility page. New classes and methods 196ac7032dSJohn Scipione and incompatible API changes to the BeOS R5 API are noted in the 206ac7032dSJohn Scipione appropriate sections. 216ac7032dSJohn Scipione 226ac7032dSJohn Scipione A complete reference to the BeOS R5 API is available on the web in 231de2d728SAugustin Cavalier <a href="https://haiku-os.org/legacy-docs/bebook/">The Be Book</a>. 246ac7032dSJohn Scipione The Be Book is used with permission from 254d556706SAugustin Cavalier <a href="https://www.access-company.com/">Access Co.</a>, the current 266ac7032dSJohn Scipione owners of Be's intellectual property. 270524a6a8Smahlzeit 281e994bc7SJohn Scipione \section book_kits Kits and Servers 290524a6a8Smahlzeit 306ac7032dSJohn Scipione The API is split into several kits and servers each detailing a different 316ac7032dSJohn Scipione aspect of the operating system. 326ac7032dSJohn Scipione - The \ref app is the starting point for developing applications 336ac7032dSJohn Scipione and includes classes for messaging and for interacting with 346ac7032dSJohn Scipione the rest of the system. 358786818cSJohn Scipione - The \ref game provides classes for producing game sounds and 368786818cSJohn Scipione working with full screen apps. 376ac7032dSJohn Scipione - The \ref interface is used to create responsive and attractive 386ac7032dSJohn Scipione graphical user interfaces building on the messaging facilities 396ac7032dSJohn Scipione provided by the Application Kit. 40*f122405dSAdrien Destugues - A \link interface_intro general introduction \endlink to the 41*f122405dSAdrien Destugues Interface Kit. 426ac7032dSJohn Scipione - The \link layout_intro Layout API \endlink is a new addition 436ac7032dSJohn Scipione to the Interface Kit in Haiku which provides resources to 446ac7032dSJohn Scipione layout your application flexibly and easily. 456ac7032dSJohn Scipione - The \ref locale includes classes to localize your application to 466ac7032dSJohn Scipione different languages, timezones, number formatting conventions and 476ac7032dSJohn Scipione much more. 4895c9effdSAugustin Cavalier - The \ref mail includes classes to work with e-mail files, folders, 4995c9effdSAugustin Cavalier protocols, and filters, as part of Haiku's unique mail handling system. 506ac7032dSJohn Scipione - The \ref media provides a unified and consistent interface for media 516ac7032dSJohn Scipione streams and applications to intercommunicate. 526ac7032dSJohn Scipione - The \ref midi2 describes an interface to generating, processing, 536ac7032dSJohn Scipione and playing music in MIDI format. For reference documentation on the 546ac7032dSJohn Scipione \ref midi1 is also included. 554cf62172SAdrien Destugues - The \ref network handles everything network related, from interface 564cf62172SAdrien Destugues IP address settings to HTTP connections. 576ac7032dSJohn Scipione - The \ref storage is a collection of classes that deal with storing and 586ac7032dSJohn Scipione retrieving information from disk. 596ac7032dSJohn Scipione - The \ref support contains support classes to use in your application 606ac7032dSJohn Scipione including resources for thread safety, IO, and serialization. 613528f5bbSJohn Scipione - The \ref translation provides a framework for converting data streams 623528f5bbSJohn Scipione between media formats. 6389e18a51SNiels Sascha Reedijk 641e994bc7SJohn Scipione \section book_special_topics Special Topics 656ac7032dSJohn Scipione 66b966e837SAdrien Destugues - \ref libroot 676ac7032dSJohn Scipione - \ref drivers 684466b89cSJohn Scipione - \ref keyboard 69f943fa46SAndrew Lindesay - \ref json 70094b8dcfSNiels Sascha Reedijk - \ref netservices 71d419ca3bSNiels Sascha Reedijk*/ 72d419ca3bSNiels Sascha Reedijk 739889ca4aSNiels Sascha Reedijk///// Define main kits ///// 7489e18a51SNiels Sascha Reedijk 75d419ca3bSNiels Sascha Reedijk/*! 76bef614efSNiels Sascha Reedijk \defgroup app Application Kit 776ac7032dSJohn Scipione \brief The Application Kit is the starting point for writing native Haiku 786ac7032dSJohn Scipione GUI applications. 796ac7032dSJohn Scipione 806ac7032dSJohn Scipione The application kit is exactly what its name suggests — it is the 816ac7032dSJohn Scipione basis of Haiku applications. You should first read through this document 826ac7032dSJohn Scipione and the references here before moving on to the other parts of the API. 836ac7032dSJohn Scipione 846ac7032dSJohn Scipione The Application Kit classes can be divided into two groups: the messaging 856ac7032dSJohn Scipione classes and the system interaction classes. The larger of the two groups is 866ac7032dSJohn Scipione the messaging classes. Since the Haiku API relies on pervasive 876ac7032dSJohn Scipione multithreading messaging is an essential topic for any application. Have a 886ac7032dSJohn Scipione look at the \link app_messaging Introduction to Messaging \endlink for more 896ac7032dSJohn Scipione information. 906ac7032dSJohn Scipione 916ac7032dSJohn Scipione The following messaging classes which allow you to easily and securely 926ac7032dSJohn Scipione communicate between threads. 936ac7032dSJohn Scipione - BHandler 946ac7032dSJohn Scipione - BInvoker 956ac7032dSJohn Scipione - BLooper 966ac7032dSJohn Scipione - BMessage 976ac7032dSJohn Scipione - BMessageFilter 986ac7032dSJohn Scipione - BMessageQueue 996ac7032dSJohn Scipione - BMessageRunner 1006ac7032dSJohn Scipione - BMessenger 1016ac7032dSJohn Scipione 1026ac7032dSJohn Scipione The second group is the system interaction classes. These classes 1036ac7032dSJohn Scipione provide hooks for your application to interact with the rest of the system. 1046ac7032dSJohn Scipione The most important class in this group is BApplication. Below is a list of 1056ac7032dSJohn Scipione all system interaction classes: 1066ac7032dSJohn Scipione - BApplication 1076ac7032dSJohn Scipione - BClipboard 1086ac7032dSJohn Scipione - BCursor 1090e6f9572SNiels Sascha Reedijk - BLaunchRoster 1100e6f9572SNiels Sascha Reedijk - BNotification 1116ac7032dSJohn Scipione - BPropertyInfo 1126ac7032dSJohn Scipione - BRoster 1136ac7032dSJohn Scipione 1140e6f9572SNiels Sascha Reedijk A third special category is the \link app_keystore Password and Key storage 1150e6f9572SNiels Sascha Reedijk API:\endlink 1160e6f9572SNiels Sascha Reedijk - BKey 1170e6f9572SNiels Sascha Reedijk - BKeyStore 1180e6f9572SNiels Sascha Reedijk 1196ac7032dSJohn Scipione 1208786818cSJohn Scipione \defgroup game Game Kit 1218786818cSJohn Scipione \brief The Game Kit provides classes for producing game sounds and 1228786818cSJohn Scipione working with full screen apps. 1238786818cSJohn Scipione 1248786818cSJohn Scipione 125cc19e7c0SAlex Wilson \defgroup interface Interface Kit 126cc19e7c0SAlex Wilson \brief API for displaying a graphical user interface. 1276ac7032dSJohn Scipione 1286ac7032dSJohn Scipione The Interface Kit holds all the classes you'll need to develop a GUI. 1296ac7032dSJohn Scipione Building on the messaging facilities provided by the Application Kit, 1306ac7032dSJohn Scipione the Interface Kit can be used to create a responsive and attractive 1316ac7032dSJohn Scipione graphical user interface. 1326ac7032dSJohn Scipione 1336ac7032dSJohn Scipione The most important class in the Interface Kit is the BView class, which 1346ac7032dSJohn Scipione handles drawing and user interaction. Pointer and keyboard events are 1356ac7032dSJohn Scipione processed in this class. 1366ac7032dSJohn Scipione 1376ac7032dSJohn Scipione Another important class is the BWindow class, which holds BViews and makes 1386ac7032dSJohn Scipione them visible to the user. The BWindow class also handles BView focusing 1396ac7032dSJohn Scipione and BMessage dispatching, among other things. 1406ac7032dSJohn Scipione 1416ac7032dSJohn Scipione A new addition Haiku has added over the BeOS API is the Layout API, which 1426ac7032dSJohn Scipione is based around the BLayoutItem and BLayout classes. These classes will 1436ac7032dSJohn Scipione take care of making sure all your GUI widgets end up where you want them, 1446ac7032dSJohn Scipione with enough space to be useful. You can start learning the Layout API 1456ac7032dSJohn Scipione by reading the \link layout_intro introduction \endlink. 1466ac7032dSJohn Scipione 1476ac7032dSJohn Scipione 1480a4e27c5SAdrien Destugues \defgroup locale Locale Kit 149c6247544SAdrien Destugues \brief Collection of classes for localizing applications. 1506ac7032dSJohn Scipione 15195c9effdSAugustin Cavalier \defgroup mail Mail Kit 15295c9effdSAugustin Cavalier \brief API for working with e-mail messages and protocols. 15395c9effdSAugustin Cavalier 1546ac7032dSJohn Scipione \defgroup media Media Kit 1556ac7032dSJohn Scipione \brief Collection of classes that deal with audio and video. 1566ac7032dSJohn Scipione 1576ac7032dSJohn Scipione \defgroup midi1 The old MIDI Kit (libmidi.so) 1586ac7032dSJohn Scipione \brief The old MIDI kit. 1596ac7032dSJohn Scipione 1606ac7032dSJohn Scipione 1616ac7032dSJohn Scipione \defgroup midi2 MIDI 2 Kit 1626ac7032dSJohn Scipione \brief The Midi Kit is the API that implements support for generating, 1636ac7032dSJohn Scipione processing, and playing music in MIDI format. 1646ac7032dSJohn Scipione 1654d556706SAugustin Cavalier <A HREF="https://www.midi.org/">MIDI</A>, which stands for 'Musical 1666ac7032dSJohn Scipione Instrument Digital Interface', is a well-established standard for 1676ac7032dSJohn Scipione representing and communicating musical data. This document serves as 1686ac7032dSJohn Scipione an overview. If you would like to see all the components, please look 1696ac7032dSJohn Scipione at \link midi2 the list with classes \endlink. 1706ac7032dSJohn Scipione 1711e994bc7SJohn Scipione \section book_midi2twokits A Tale of Two MIDI Kits 1726ac7032dSJohn Scipione 1736ac7032dSJohn Scipione BeOS comes with two different, but compatible Midi Kits. This 1746ac7032dSJohn Scipione documentation focuses on the "new" Midi Kit, or midi2 as we like to 1756ac7032dSJohn Scipione call it, that was introduced with BeOS R5. The old kit, which we'll 1766ac7032dSJohn Scipione refer to as midi1, is more complete than the new kit, but less powerful. 1776ac7032dSJohn Scipione 1786ac7032dSJohn Scipione Both kits let you create so-called MIDI endpoints, but the endpoints 1796ac7032dSJohn Scipione from midi1 cannot be shared between different applications. The midi2 1806ac7032dSJohn Scipione kit solves that problem, but unlike midi1 it does not include a General 1816ac7032dSJohn Scipione MIDI softsynth, nor does it have a facility for reading and playing 1826ac7032dSJohn Scipione Standard MIDI Files. Don't worry: both kits are compatible and you can 1836ac7032dSJohn Scipione mix-and-match them in your applications. 1846ac7032dSJohn Scipione 1856ac7032dSJohn Scipione The main differences between the two kits: 1866ac7032dSJohn Scipione - Instead of one BMidi object that both produces and consumes events, 1876ac7032dSJohn Scipione we have BMidiProducer and BMidiConsumer. 1886ac7032dSJohn Scipione - Applications are capable of sharing MIDI producers and consumers 1896ac7032dSJohn Scipione with other applications via the centralized Midi Roster. 1906ac7032dSJohn Scipione - Physical MIDI ports are now sharable without apps "stealing" events 1916ac7032dSJohn Scipione from each other. 1926ac7032dSJohn Scipione - Applications can now send/receive raw MIDI byte streams (useful if 1936ac7032dSJohn Scipione an application has its own MIDI parser/engine). 1946ac7032dSJohn Scipione - Channels are numbered 0–15, not 1–16 1956ac7032dSJohn Scipione - Timing is now specified in microseconds rather than milliseconds. 1966ac7032dSJohn Scipione 1971e994bc7SJohn Scipione \section book_midi2concepts Midi Kit Concepts 1986ac7032dSJohn Scipione 1996ac7032dSJohn Scipione A brief overview of the elements that comprise the Midi Kit: 2006ac7032dSJohn Scipione - \b Endpoints. This is what the Midi Kit is all about: sending MIDI 2016ac7032dSJohn Scipione messages between endpoints. An endpoint is like a MIDI In or MIDI 2026ac7032dSJohn Scipione Out socket on your equipment; it either receives information or it 2036ac7032dSJohn Scipione sends information. Endpoints that send MIDI events are called 2046ac7032dSJohn Scipione \b producers; the endpoints that receive those events are called 2056ac7032dSJohn Scipione \b consumers. An endpoint that is created by your own application 2066ac7032dSJohn Scipione is called \b local; endpoints from other applications are 2076ac7032dSJohn Scipione \b remote. You can access remote endpoints using \b proxies. 2086ac7032dSJohn Scipione - \b Filters. A filter is an object that has a consumer and a producer 2096ac7032dSJohn Scipione endpoint. It reads incoming events from its consumer, performs some 2106ac7032dSJohn Scipione operation, and tells its producer to send out the results. In its 2116ac7032dSJohn Scipione current form, the Midi Kit doesn't provide any special facilities 2126ac7032dSJohn Scipione for writing filters. 2136ac7032dSJohn Scipione - \b Midi \b Roster. The roster is the list of all published producers 2146ac7032dSJohn Scipione and consumers. By publishing an endpoint, you allow other 2156ac7032dSJohn Scipione applications to talk to it. You are not required to publish your 2166ac7032dSJohn Scipione endpoints, in which case only your own application can use them. 2176ac7032dSJohn Scipione - \b Midi \b Server. The Midi Server does the behind-the-scenes work. 2186ac7032dSJohn Scipione It manages the roster, it connects endpoints, it makes sure that 2196ac7032dSJohn Scipione endpoints can communicate, and so on. The Midi Server is started 2206ac7032dSJohn Scipione automatically when BeOS boots, and you never have to deal with it 2216ac7032dSJohn Scipione directly. Just remember that it runs the show. 2226ac7032dSJohn Scipione - \b libmidi. The BMidi* classes live inside two shared libraries: 2236ac7032dSJohn Scipione libmidi.so and libmidi2.so. If you write an application that uses 2246ac7032dSJohn Scipione old Midi Kit, you must link it to libmidi.so. Applications that use 2256ac7032dSJohn Scipione the new Midi Kit must link to libmidi2.so. If you want to 2266ac7032dSJohn Scipione mix-and-match both kits, you should also link to both libraries. 2276ac7032dSJohn Scipione 2286ac7032dSJohn Scipione Here is a pretty picture: 2296ac7032dSJohn Scipione 2306ac7032dSJohn Scipione \image html midi2concepts.png 2316ac7032dSJohn Scipione 2321e994bc7SJohn Scipione \section book_midi2mediakit Midi Kit != Media Kit 2336ac7032dSJohn Scipione 2346ac7032dSJohn Scipione Be chose not to integrate the Midi Kit into the Media Kit as another media 2356ac7032dSJohn Scipione type, mainly because MIDI doesn't require any of the format negotiation that 2366ac7032dSJohn Scipione other media types need. Although the two kits look similar -- both have a 2376ac7032dSJohn Scipione "roster" for finding or registering "consumers" and "producers" -- there are 2386ac7032dSJohn Scipione some very important differences. 2396ac7032dSJohn Scipione 2406ac7032dSJohn Scipione The first and most important point to note is that BMidiConsumer and 2416ac7032dSJohn Scipione BMidiProducer in the Midi Kit are \b NOT directly analogous to 2426ac7032dSJohn Scipione BBufferConsumer and BBufferProducer in the Media Kit! In the Media Kit, 2436ac7032dSJohn Scipione consumers and producers are the data consuming and producing properties 2446ac7032dSJohn Scipione of a media node. A filter in the Media Kit, therefore, inherits from both 2456ac7032dSJohn Scipione BBufferConsumer and BBufferProducer, and implements their virtual member 2466ac7032dSJohn Scipione functions to do its work. 2476ac7032dSJohn Scipione 2486ac7032dSJohn Scipione In the Midi Kit, consumers and producers act as endpoints of MIDI data 2496ac7032dSJohn Scipione connections, much as media_source and media_destination do in the Media Kit. 2506ac7032dSJohn Scipione Thus, a MIDI filter does not derive from BMidiConsumer and BMidiProducer; 2516ac7032dSJohn Scipione instead, it contains BMidiConsumer and BMidiProducer objects for each of its 2526ac7032dSJohn Scipione distinct endpoints that connect to other MIDI objects. The Midi Kit does not 2536ac7032dSJohn Scipione allow the use of multiple virtual inheritance, so you can't create an object 2546ac7032dSJohn Scipione that's both a BMidiConsumer and a BMidiProducer. 2556ac7032dSJohn Scipione 2566ac7032dSJohn Scipione This also contrasts with the old Midi Kit's conception of a BMidi object, 2576ac7032dSJohn Scipione which stood for an object that both received and sent MIDI data. In the new 2586ac7032dSJohn Scipione Midi Kit, the endpoints of MIDI connections are all that matters. What lies 2596ac7032dSJohn Scipione between the endpoints, i.e. how a MIDI filter is actually structured, is 2606ac7032dSJohn Scipione entirely at your discretion. 2616ac7032dSJohn Scipione 2626ac7032dSJohn Scipione Also, rather than use token structs like media_node to make connections 2636ac7032dSJohn Scipione via the MediaRoster, the new kit makes the connections directly via the 2646ac7032dSJohn Scipione BMidiProducer object. 2656ac7032dSJohn Scipione 2661e994bc7SJohn Scipione \section book_midi2remotelocal Remote vs. Local Objects 2676ac7032dSJohn Scipione 2686ac7032dSJohn Scipione The Midi Kit makes a distinction between remote and local MIDI objects. 2696ac7032dSJohn Scipione You can only create local MIDI endpoints, which derive from either 2706ac7032dSJohn Scipione BMidiLocalConsumer or BMidiLocalProducer. Remote endpoints are endpoints 2716ac7032dSJohn Scipione that live in other applications, and you access them through BMidiRoster. 2726ac7032dSJohn Scipione 2736ac7032dSJohn Scipione BMidiRoster only gives you access to BMidiEndpoints, BMidiConsumers, and 2746ac7032dSJohn Scipione BMidiProducers. When you want to talk to remote MIDI objects, you do so 2756ac7032dSJohn Scipione through the proxy objects that BMidiRoster provides. Unlike 2766ac7032dSJohn Scipione BMidiLocalConsumer and BMidiLocalProducer, these classes do not provide a 2776ac7032dSJohn Scipione lot of functions. That is intentional. In order to hide the details of 2786ac7032dSJohn Scipione communication with MIDI endpoints in other applications, the Midi Kit must 2796ac7032dSJohn Scipione hide the details of how a particular endpoint is implemented. 2806ac7032dSJohn Scipione 2816ac7032dSJohn Scipione So what can you do with remote objects? Only what BMidiConsumer, 2826ac7032dSJohn Scipione BMidiProducer, and BMidiEndpoint will let you do. You can connect 2836ac7032dSJohn Scipione objects, get the properties of these objects -- and that's about it. 2846ac7032dSJohn Scipione 2851e994bc7SJohn Scipione \section book_midi2lifespan Creating and Destroying Objects 2866ac7032dSJohn Scipione 2876ac7032dSJohn Scipione The constructors and destructors of most midi2 classes are private, 2886ac7032dSJohn Scipione which means that you cannot directly create them using the C++ 2896ac7032dSJohn Scipione <CODE>new</CODE> operator, on the stack, or as globals. Nor can you 2906ac7032dSJohn Scipione <CODE>delete</CODE> them. Instead, these objects are obtained through 2916ac7032dSJohn Scipione BMidiRoster. The only two exceptions to this rule are BMidiLocalConsumer 2926ac7032dSJohn Scipione and BMidiLocalProducer. These two objects may be directly created and 2936ac7032dSJohn Scipione subclassed by developers. 2946ac7032dSJohn Scipione 2951e994bc7SJohn Scipione \section book_midi2refcount Reference Counting 2966ac7032dSJohn Scipione 2976ac7032dSJohn Scipione Each MIDI endpoint has a reference count associated with it, so that 2986ac7032dSJohn Scipione the Midi Roster can do proper bookkeeping. When you construct a 2996ac7032dSJohn Scipione BMidiLocalProducer or BMidiLocalConsumer endpoint, it starts with a 3006ac7032dSJohn Scipione reference count of 1. In addition, BMidiRoster increments the reference 3016ac7032dSJohn Scipione count of any object it hands to you as a result of 3026ac7032dSJohn Scipione \link BMidiRoster::NextEndpoint() NextEndpoint() \endlink or 3036ac7032dSJohn Scipione \link BMidiRoster::FindEndpoint() FindEndpoint() \endlink. 3046ac7032dSJohn Scipione Once the count hits 0, the endpoint will be deleted. 3056ac7032dSJohn Scipione 3066ac7032dSJohn Scipione This means that, to delete an endpoint, you don't call the 3076ac7032dSJohn Scipione <CODE>delete</CODE> operator directly; instead, you call 3086ac7032dSJohn Scipione \link BMidiEndpoint::Release() Release() \endlink. 3096ac7032dSJohn Scipione To balance this call, there's also an 3106ac7032dSJohn Scipione \link BMidiEndpoint::Acquire() Acquire() \endlink, in case you have two 3116ac7032dSJohn Scipione disparate parts of your application working with the endpoint, and you 3126ac7032dSJohn Scipione don't want to have to keep track of who needs to Release() the endpoint. 3136ac7032dSJohn Scipione 3146ac7032dSJohn Scipione When you're done with any endpoint object, you must Release() it. 3156ac7032dSJohn Scipione This is true for both local and remote objects. Repeat after me: 3166ac7032dSJohn Scipione Release() when you're done. 3176ac7032dSJohn Scipione 3181e994bc7SJohn Scipione \section book_midi2events MIDI Events 3196ac7032dSJohn Scipione 3206ac7032dSJohn Scipione To make some actual music, you need to 3216ac7032dSJohn Scipione \link BMidiProducer::Connect() Connect() \endlink your consumers to 3226ac7032dSJohn Scipione your producers. Then you tell the producer to "spray" MIDI events to all 3236ac7032dSJohn Scipione the connected consumers. The consumers are notified of these incoming 3246ac7032dSJohn Scipione events through a set of hook functions. 3256ac7032dSJohn Scipione 3266ac7032dSJohn Scipione The Midi Kit already provides a set of commonly used spray functions, 3276ac7032dSJohn Scipione such as \link BMidiLocalProducer::SprayNoteOn() SprayNoteOn() \endlink, 3286ac7032dSJohn Scipione \link BMidiLocalProducer::SprayControlChange() SprayControlChange() 3296ac7032dSJohn Scipione \endlink, and so on. These correspond one-to-one with the message types 3306ac7032dSJohn Scipione from the MIDI spec. You don't need to be a MIDI expert to use the kit, but 3316ac7032dSJohn Scipione of course some knowledge of the protocol helps. If you are really hardcore, 3326ac7032dSJohn Scipione you can also use the 3336ac7032dSJohn Scipione \link BMidiLocalProducer::SprayData() SprayData() \endlink to send raw MIDI 3346ac7032dSJohn Scipione events to the consumers. 3356ac7032dSJohn Scipione 3366ac7032dSJohn Scipione At the consumer side, a dedicated thread invokes a hook function for every 3376ac7032dSJohn Scipione incoming MIDI event. For every spray function, there is a corresponding hook 3386ac7032dSJohn Scipione function, e.g. \link BMidiLocalConsumer::NoteOn() NoteOn() \endlink and 3396ac7032dSJohn Scipione \link BMidiLocalConsumer::ControlChange() ControlChange() \endlink. 3406ac7032dSJohn Scipione The hardcore MIDI fanatics among you will be pleased to know that you can 3416ac7032dSJohn Scipione also tap into the \link BMidiLocalConsumer::Data() Data() \endlink hook and 3426ac7032dSJohn Scipione get your hands dirty with the raw MIDI data. 3436ac7032dSJohn Scipione 3441e994bc7SJohn Scipione \section book_midi2time Time 3456ac7032dSJohn Scipione 3466ac7032dSJohn Scipione The spray and hook functions accept a bigtime_t parameter named "time". This 3476ac7032dSJohn Scipione indicates when the MIDI event should be performed. The time is given in 3486ac7032dSJohn Scipione microseconds since the computer booted. To get the current tick measurement, 3496ac7032dSJohn Scipione you call the system_time() function from the Kernel Kit. 3506ac7032dSJohn Scipione 3516ac7032dSJohn Scipione If you override a hook function in one of your consumer objects, it should 3526ac7032dSJohn Scipione look at the time argument, wait until the designated time, and then perform 3536ac7032dSJohn Scipione its action. The preferred method is to use the Kernel Kit's 3546ac7032dSJohn Scipione <CODE>snooze_until()</CODE> function, which sends the consumer thread to 3556ac7032dSJohn Scipione sleep until the requested time has come. (Or, if the time has already 3566ac7032dSJohn Scipione passed, returns immediately.) 3576ac7032dSJohn Scipione 3586ac7032dSJohn Scipione Like this: 3596ac7032dSJohn Scipione 3606ac7032dSJohn Scipione \code 3616ac7032dSJohn Scipionevoid MyConsumer::NoteOn( 3626ac7032dSJohn Scipione uchar channel, uchar note, uchar velocity, bigtime_t time) 3636ac7032dSJohn Scipione{ 3646ac7032dSJohn Scipione snooze_until(time, B_SYSTEM_TIMEBASE); 3656ac7032dSJohn Scipione ...do your thing... 3666ac7032dSJohn Scipione} 3676ac7032dSJohn Scipione \endcode 3686ac7032dSJohn Scipione 3696ac7032dSJohn Scipione If you want your producers to run in real time, i.e. they produce MIDI data 3706ac7032dSJohn Scipione that needs to be performed immediately, you should pass time 0 to the spray 3716ac7032dSJohn Scipione functions (which also happens to be the default value). Since time 0 has 3726ac7032dSJohn Scipione already passed, <CODE>snooze_until()</CODE> returns immediately, and the 3736ac7032dSJohn Scipione consumer will process the events as soon as they are received. 3746ac7032dSJohn Scipione 3756ac7032dSJohn Scipione To schedule MIDI events for a performance time that lies somewhere in the 3766ac7032dSJohn Scipione future, the producer must take into account the consumer's latency. 3776ac7032dSJohn Scipione Producers should attempt to get notes to the consumer by or before 3786ac7032dSJohn Scipione <I>(scheduled_performance_time - latency)</I>. The time argument is still 3796ac7032dSJohn Scipione the scheduled performance time, so if your consumer has latency, it should 3806ac7032dSJohn Scipione snooze like this before it starts to perform the events: 3816ac7032dSJohn Scipione 3826ac7032dSJohn Scipione \code 3836ac7032dSJohn Scipionesnooze_until(time - Latency(), B_SYSTEM_TIMEBASE); 3846ac7032dSJohn Scipione \endcode 3856ac7032dSJohn Scipione 3866ac7032dSJohn Scipione Note that a typical producer sends out its events as soon as it can; 3876ac7032dSJohn Scipione unlike a consumer, it does not have to snooze. 3886ac7032dSJohn Scipione 3891e994bc7SJohn Scipione \section book_midi2ports Other Timing Issues 3906ac7032dSJohn Scipione 3916ac7032dSJohn Scipione Each consumer object uses a Kernel Kit port to receive MIDI events from 3926ac7032dSJohn Scipione connected producers. The queue for this port is only 1 message deep. 3936ac7032dSJohn Scipione This means that if the consumer thread is asleep in a 3946ac7032dSJohn Scipione <CODE>snooze_until()</CODE>, it will not read its port. Consequently, 3956ac7032dSJohn Scipione any producer that tries to write a new event to this port will block until 3966ac7032dSJohn Scipione the consumer thread is ready to receive a new message. This is intentional, 3976ac7032dSJohn Scipione because it prevents producers from generating and queueing up thousands of 3986ac7032dSJohn Scipione events. 3996ac7032dSJohn Scipione 4006ac7032dSJohn Scipione This mechanism, while simple, puts on the producer the responsibility 4016ac7032dSJohn Scipione for sorting the events in time. Suppose your producer sends three Note 4026ac7032dSJohn Scipione On events, the first on t + 0, the second on t + 4, and the third on t + 2. 4036ac7032dSJohn Scipione This last event won't be received until after t + 4, so it will be two ticks 4046ac7032dSJohn Scipione too late. If this sort of thing can happen with your producer, you should 4056ac7032dSJohn Scipione somehow sort the events before you spray them. Of course, if you have two or 4066ac7032dSJohn Scipione more producers connected to the same consumer, it is nearly impossible to 4076ac7032dSJohn Scipione sort this all out (pardon the pun). So it is not wise to send the same kinds 4086ac7032dSJohn Scipione of events from more than one producer to one consumer at the same time. 4096ac7032dSJohn Scipione 4106ac7032dSJohn Scipione The article Introduction to MIDI, Part 2 in <A 4114d556706SAugustin Cavalier HREF="https://open-beos.sourceforge.net/nsl.php?mode=display&id=36">OpenBeOS 4126ac7032dSJohn Scipione Newsletter 36</A> describes this problem in more detail, and provides a 4136ac7032dSJohn Scipione solution. Go read it now! 4146ac7032dSJohn Scipione 4151e994bc7SJohn Scipione \section book_midi2filters Writing a Filter 4166ac7032dSJohn Scipione 4176ac7032dSJohn Scipione A typical filter contains a consumer and a producer endpoint. It receives 4186ac7032dSJohn Scipione events from the consumer, processes them, and sends them out again using the 4196ac7032dSJohn Scipione producer. The consumer endpoint is a subclass of BMidiLocalConsumer, whereas 4206ac7032dSJohn Scipione the producer is simply a BMidiLocalProducer, not a subclass. This is a 4216ac7032dSJohn Scipione common configuration, because consumers work by overriding the event hooks 4226ac7032dSJohn Scipione to do work when MIDI data arrives. Producers work by sending an event when 4236ac7032dSJohn Scipione you call their member functions. You should hardly ever need to derive from 4246ac7032dSJohn Scipione BMidiLocalProducer (unless you need to know when the producer gets connected 4256ac7032dSJohn Scipione or disconnected, perhaps), but you'll always have to override one or more of 4266ac7032dSJohn Scipione BMidiLocalConsumer's member functions to do something useful with incoming 4276ac7032dSJohn Scipione data. 4286ac7032dSJohn Scipione 4296ac7032dSJohn Scipione Filters should ignore the time argument from the spray and hook functions, 4306ac7032dSJohn Scipione and simply pass it on unchanged. Objects that only filter data should 4316ac7032dSJohn Scipione process the event as quickly as possible and be done with it. Do not 4326ac7032dSJohn Scipione <CODE>snooze_until()</CODE> in the consumer endpoint of a filter! 4336ac7032dSJohn Scipione 4341e994bc7SJohn Scipione \section book_midi2apidiffs API Differences 4356ac7032dSJohn Scipione 4366ac7032dSJohn Scipione As far as the end user is concerned, the Haiku Midi Kit is mostly the same 4376ac7032dSJohn Scipione as the BeOS R5 kits, although there are a few small differences in the API 4386ac7032dSJohn Scipione (mostly bug fixes): 4396ac7032dSJohn Scipione - BMidiEndpoint::IsPersistent() always returns false. 4406ac7032dSJohn Scipione - The B_MIDI_CHANGE_LATENCY notification is now properly sent. The Be 4416ac7032dSJohn Scipione kit incorrectly set be:op to B_MIDI_CHANGED_NAME, even though the 4426ac7032dSJohn Scipione rest of the message was properly structured. 4436ac7032dSJohn Scipione - If creating a local endpoint fails, you can still Release() the object 4446ac7032dSJohn Scipione without crashing into the debugger. 4456ac7032dSJohn Scipione 4461e994bc7SJohn Scipione \section book_midi2seealso See also 4476ac7032dSJohn Scipione 4486ac7032dSJohn Scipione More about the Midi Kit: 4496ac7032dSJohn Scipione - \ref Midi2Defs.h 4506ac7032dSJohn Scipione - Be Newsletter Volume 3, Issue 47 - Motor Mix sample code 4516ac7032dSJohn Scipione - Be Newsletter Volume 4, Issue 3 - Overview of the new kit 4524d556706SAugustin Cavalier - <A HREF="https://haiku-os.org/documents/dev/introduction_to_midi_part_1">Newsletter 4536ac7032dSJohn Scipione 33</A>, Introduction to MIDI, Part 1 4544d556706SAugustin Cavalier - <A HREF="https://haiku-os.org/documents/dev/introduction_to_midi_part_2">Newsletter 4556ac7032dSJohn Scipione 36</A>, Introduction to MIDI, Part 2 4566ac7032dSJohn Scipione - Sample code and other goodies at the 4574d556706SAugustin Cavalier <A HREF="https://haiku-os.org/about/teams/midi_kit">Haiku Midi Kit team page</A> 4586ac7032dSJohn Scipione 4596ac7032dSJohn Scipione Information about MIDI in general: 4604d556706SAugustin Cavalier - <A HREF="https://www.midi.org">MIDI Manufacturers Association</A> 4614d556706SAugustin Cavalier - <A HREF="https://www.borg.com/~jglatt/tutr/miditutr.htm">MIDI Tutorials</A> 4624d556706SAugustin Cavalier - <A HREF="https://www.borg.com/~jglatt/tech/midispec.htm">MIDI Specification</A> 4634d556706SAugustin Cavalier - <A HREF="https://www.borg.com/~jglatt/tech/midifile.htm">Standard MIDI File Format</A> 4644d556706SAugustin Cavalier - <A HREF="https://www.io.com/~jimm/midi_ref.html">Jim Menard's MIDI Reference</A> 4656ac7032dSJohn Scipione 4666ac7032dSJohn Scipione 4674cf62172SAdrien Destugues \defgroup network Network Kit 4684cf62172SAdrien Destugues \brief Classes that deal with all network connections and communications. 4696ac7032dSJohn Scipione 470b1a9f638SJohn Scipione The Haiku Network Kit consists of: 471b1a9f638SJohn Scipione - A modular, add-ons based network stack 47295c9effdSAugustin Cavalier - Two shared libraries, libnetwork.so and libnetapi.so 473b1a9f638SJohn Scipione - A stack driver, acting as interface between the network stack and 47495c9effdSAugustin Cavalier libnetwork.so 475b1a9f638SJohn Scipione - Basic network apps 476b1a9f638SJohn Scipione - A modular GUI preflet 477b1a9f638SJohn Scipione 478b1a9f638SJohn Scipione The libnet.so shared library is the way that BeOS R5 provided POSIX/BSD 479b1a9f638SJohn Scipione API sockets to apps. Being binary compatible with BeOS R5 has made this 480b1a9f638SJohn Scipione library implementation tedious. To counter this, the libnetapi.so shared 481b1a9f638SJohn Scipione library was developed. It contains thin C++ classes wrapping the C 482b1a9f638SJohn Scipione sockets POSIX/BSD API into these BNet* classes we're used under BeOS. 483b1a9f638SJohn Scipione 484b1a9f638SJohn Scipione The stack driver is the interface between libnet.so and the real stack 485b1a9f638SJohn Scipione behind it, hosted by the network stack kernel modules. Its purposes 486b1a9f638SJohn Scipione include: 487b1a9f638SJohn Scipione -# Providing sockets to file descriptors translation support 488b1a9f638SJohn Scipione -# Providing support for select() on sockets 489b1a9f638SJohn Scipione -# Loading the network stack on first access, and then keeping it for 490b1a9f638SJohn Scipione further accesses 491b1a9f638SJohn Scipione 492b1a9f638SJohn Scipione The following diagram illustrates the network stack design on Haiku: 493b1a9f638SJohn Scipione 494b1a9f638SJohn Scipione \image html obos_net_stack_design_1.gif 495b1a9f638SJohn Scipione 496b1a9f638SJohn Scipione The Network Kit includes a handful of useful networking related apps 497b1a9f638SJohn Scipione including ping, ifconfig, route, traceroute, and arp. 498b1a9f638SJohn Scipione 499b1a9f638SJohn Scipione See the User Guide for more information about the 5004d556706SAugustin Cavalier <a href="https://haiku-os.org/docs/userguide/en/preferences/network.html">Network preferences app</a> 501b1a9f638SJohn Scipione included as part of the Network Kit. 502b1a9f638SJohn Scipione 503b1a9f638SJohn Scipione 5046ac7032dSJohn Scipione \defgroup storage Storage Kit 5056ac7032dSJohn Scipione \brief Collection of classes that deal with storing and retrieving 5066ac7032dSJohn Scipione information from disk. 5076ac7032dSJohn Scipione 5086ac7032dSJohn Scipione 5096ac7032dSJohn Scipione \defgroup support Support Kit 5106ac7032dSJohn Scipione \brief Collection of utility classes that are used throughout the API. 5116ac7032dSJohn Scipione 5126ac7032dSJohn Scipione The Support Kit provides a handy set of classes that you can use in your 5136ac7032dSJohn Scipione applications. These classes provide: 5146ac7032dSJohn Scipione - \b Thread \b Safety. Haiku can execute multiple threads of an 5156ac7032dSJohn Scipione application in parallel, letting certain parts of an application 5166ac7032dSJohn Scipione continue when one part is stalled, as well as letting an application 5176ac7032dSJohn Scipione process multiple pieces of data at the same time on multicore or 5186ac7032dSJohn Scipione multiprocessor systems. However, there are times when multiple 5196ac7032dSJohn Scipione threads desire to work on the same piece of data at the same time, 5206ac7032dSJohn Scipione potentially causing a conflict where variables or pointers are 5216ac7032dSJohn Scipione changed by one thread causing another to execute incorrectly. To 5226ac7032dSJohn Scipione prevent this, Haiku implements a \"locking\" mechanism, allowing one 5236ac7032dSJohn Scipione thread to \"lock out\" other threads from executing code that might 5246ac7032dSJohn Scipione modify the same data. 5256ac7032dSJohn Scipione - \b Archiving \b and \b IO. These classes allow a programmer to 5266ac7032dSJohn Scipione convert objects into a form that can more easily be transferred to 5276ac7032dSJohn Scipione other applications or stored to disk, as well as performing basic 5286ac7032dSJohn Scipione input and output operations. 5296ac7032dSJohn Scipione - \b Memory \b Allocation. This class allows a programmer to hand off 5306ac7032dSJohn Scipione some of the duties of memory accounting and management. 5316ac7032dSJohn Scipione - \b Common \b Datatypes. To avoid unnecessary duplication of code 5326ac7032dSJohn Scipione and to make life easier for programmers, Haiku includes classes that 5336ac7032dSJohn Scipione handle management of ordered lists and strings. 5346ac7032dSJohn Scipione 5356ac7032dSJohn Scipione There are also a number of utility functions to time actions, play system 5366ac7032dSJohn Scipione alert sounds, compare strings, and atomically manipulate integers. Have a 5376ac7032dSJohn Scipione look at the overview, or go straight to the complete 5386ac7032dSJohn Scipione \link support list of components \endlink of this kit. 5396ac7032dSJohn Scipione 5401e994bc7SJohn Scipione \section book_overview Overview 5416ac7032dSJohn Scipione - Thread Safety: 5426ac7032dSJohn Scipione - BLocker provides a semaphore-like locking mechanism allowing for 5436ac7032dSJohn Scipione recursive locks. 5446ac7032dSJohn Scipione - BAutolock provides a simple method of automatically removing a 5456ac7032dSJohn Scipione lock when a function ends. 5466ac7032dSJohn Scipione - \ref TLS.h "Thread Local Storage" allows a global variable\'s 5476ac7032dSJohn Scipione content to be sensitive to thread context. 5486ac7032dSJohn Scipione - Archiving and IO: 5496ac7032dSJohn Scipione - BArchivable provides an interface for \"archiving\" objects so 5506ac7032dSJohn Scipione that they may be sent to other applications where an identical 5516ac7032dSJohn Scipione copy will be recreated. 5526ac7032dSJohn Scipione - BArchiver simplifies archiving of BArchivable hierarchies. 5536ac7032dSJohn Scipione - BUnarchiver simplifies unarchiving hierarchies that have been 5546ac7032dSJohn Scipione archived using BArchiver. 5556ac7032dSJohn Scipione - BFlattenable provides an interface for \"flattening\" objects so 5566ac7032dSJohn Scipione that they may be easily stored to disk. 5576ac7032dSJohn Scipione - BDataIO provides an interface for generalized read/write streams. 5586ac7032dSJohn Scipione - BPositionIO extends BDataIO to allow seeking within the data. 5596ac7032dSJohn Scipione - BBufferIO creates a buffer and attaches it to a BPositionIO 5606ac7032dSJohn Scipione stream, allowing for reduced load on the underlying stream. 5616ac7032dSJohn Scipione - BMemoryIO allows operation on an already-existing buffer. 5626ac7032dSJohn Scipione - BMallocIO creates and allows operation on a buffer. 5636ac7032dSJohn Scipione - Memory Allocation: 5646ac7032dSJohn Scipione - BBlockCache allows an application to allocate a \"pool\" of 5656ac7032dSJohn Scipione memory blocks that the application can fetch and dispose of as 5666ac7032dSJohn Scipione it pleases, letting the application make only a few large memory 5676ac7032dSJohn Scipione allocations, instead of many small expensive allocations. 5686ac7032dSJohn Scipione - Common Datatypes: 5696ac7032dSJohn Scipione - BList allows simple ordered lists and provides common access, 5706ac7032dSJohn Scipione modification, and comparison functions. 5716ac7032dSJohn Scipione - BString allows strings and provides common access, modification, 5726ac7032dSJohn Scipione and comparison functions. 5736ac7032dSJohn Scipione - BStopWatch allows an application to measure the time an action takes. 5746ac7032dSJohn Scipione - \ref support_globals "Global functions" 5756ac7032dSJohn Scipione - \ref TypeConstants.h "Common types and constants" 5766ac7032dSJohn Scipione - Error codes for all kits 5776ac7032dSJohn Scipione 5786ac7032dSJohn Scipione 5793528f5bbSJohn Scipione \defgroup translation Translation Kit 5803528f5bbSJohn Scipione \brief Provides a framework for converting data streams between media 5813528f5bbSJohn Scipione formats. 5823528f5bbSJohn Scipione 5833528f5bbSJohn Scipione 58402bdb5dbSFrançois Revol \defgroup libtranslation (libtranslation.so) 58502bdb5dbSFrançois Revol 5866ac7032dSJohn Scipione \defgroup libbe (libbe.so) 5876ac7032dSJohn Scipione 5886ac7032dSJohn Scipione 5896ac7032dSJohn Scipione \defgroup libroot (libroot.so) 590b966e837SAdrien Destugues \brief Implements the C and POSIX standard libraries. 5910524a6a8Smahlzeit*/ 5929d54b143SNiels Sascha Reedijk 5939889ca4aSNiels Sascha Reedijk///// Subgroups ///// 5949d54b143SNiels Sascha Reedijk 5959d54b143SNiels Sascha Reedijk/*! 596dba29137Swaddlesplash \defgroup support_globals Global functions 5979d54b143SNiels Sascha Reedijk \ingroup support 598cc19e7c0SAlex Wilson 599dba29137Swaddlesplash \defgroup layout Layout API 600dba29137Swaddlesplash \brief Provides classes for automatically laying out UIs. 601cc19e7c0SAlex Wilson \ingroup interface 6029d54b143SNiels Sascha Reedijk*/ 6034466b89cSJohn Scipione 6044466b89cSJohn Scipione 6054466b89cSJohn Scipione///// Special Topics ///// 6064466b89cSJohn Scipione 607aa6ef665SAugustin Cavalier/*! 6084466b89cSJohn Scipione \defgroup drivers Device Drivers 609f943fa46SAndrew Lindesay 610f943fa46SAndrew Lindesay \defgroup json Json Handling 611f943fa46SAndrew Lindesay \brief Provides for parsing and writing of data in Json encoding. 612094b8dcfSNiels Sascha Reedijk 613094b8dcfSNiels Sascha Reedijk \defgroup netservices Experimental Network Services Support 614094b8dcfSNiels Sascha Reedijk \brief Experimental API to do higher level network requests 615094b8dcfSNiels Sascha Reedijk 616094b8dcfSNiels Sascha Reedijk This API currently is marked as experimental. It is part of the 617094b8dcfSNiels Sascha Reedijk <code>BPrivate::Network</code> namespace, the header files are found at 618094b8dcfSNiels Sascha Reedijk <code>headers\\private\\netservices</code>, and you have to link your 619094b8dcfSNiels Sascha Reedijk application to <code>libnetservices.a</code>. 620aa6ef665SAugustin Cavalier*/ 621094b8dcfSNiels Sascha Reedijk 622094b8dcfSNiels Sascha Reedijk 623094b8dcfSNiels Sascha Reedijk///// Namespace Documentation ///// 624094b8dcfSNiels Sascha Reedijk 625094b8dcfSNiels Sascha Reedijk 626094b8dcfSNiels Sascha Reedijk//! \brief Internal or experimental API 627094b8dcfSNiels Sascha Reedijknamespace BPrivate { 628094b8dcfSNiels Sascha Reedijk /*! 629094b8dcfSNiels Sascha Reedijk \brief Experimental Network Services API 630094b8dcfSNiels Sascha Reedijk 631094b8dcfSNiels Sascha Reedijk See \ref netservices for more information. 632094b8dcfSNiels Sascha Reedijk */ 633094b8dcfSNiels Sascha Reedijk namespace Network { 634094b8dcfSNiels Sascha Reedijk 635094b8dcfSNiels Sascha Reedijk } 636094b8dcfSNiels Sascha Reedijk} 637